summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/file.c21
-rwxr-xr-xsrc/rename-logic.py2
-rw-r--r--test/test_e2e.py4
3 files changed, 17 insertions, 10 deletions
diff --git a/src/file.c b/src/file.c
index add198b..69fe244 100644
--- a/src/file.c
+++ b/src/file.c
@@ -319,18 +319,18 @@ static int file_fill_recursive(struct list_head *file_list,
int file_fill(sftp_session sftp, struct list_head *file_list, char **src_array, int cnt,
char *dst)
{
- bool dst_is_remote, dst_dir_no_exist, dst_should_dir;
+ bool dst_is_remote, dst_is_dir, dst_dir_no_exist, dst_should_dir;
char *dst_path, *src_path;
int n, ret;
dst_path = file_find_path(dst);
dst_path = *dst_path == '\0' ? "." : dst_path;
dst_is_remote = file_find_hostname(dst) ? true : false;
-
if (file_is_directory(dst_path, dst_is_remote ? sftp : NULL, false) > 0)
- dst_dir_no_exist = false;
+ dst_is_dir = true;
else
- dst_dir_no_exist = true;
+ dst_is_dir = false;
+ dst_dir_no_exist = !dst_is_dir;
for (n = 0; n < cnt; n++) {
src_path = file_find_path(src_array[n]);
@@ -341,8 +341,8 @@ int file_fill(sftp_session sftp, struct list_head *file_list, char **src_array,
dst_should_dir = false;
ret = file_fill_recursive(file_list, dst_is_remote, sftp,
- src_path, "",
- dst_path, dst_should_dir, dst_dir_no_exist);
+ src_path, "", dst_path,
+ dst_should_dir | dst_is_dir, dst_dir_no_exist);
if (ret < 0)
return ret;
}
@@ -471,7 +471,12 @@ int chunk_fill(struct list_head *file_list, struct list_head *chunk_list,
pr_debug("%s chunk_sz %lu-byte\n", f->src_path, chunk_sz);
- for (size = f->size; size > 0;) {
+ /* for (size = f->size; size > 0;) does not create a
+ * file (chunk) when file size is 0. This do {} while
+ * (size > 0) creates just open/close a 0-byte file.
+ */
+ size = f->size;
+ do {
c = chunk_alloc(f);
if (!c)
return -1;
@@ -481,7 +486,7 @@ int chunk_fill(struct list_head *file_list, struct list_head *chunk_list,
list_add_tail(&c->list, chunk_list);
pprint4("chunk %s 0x%010lx-0x%010lx %luB\n",
c->f->src_path, c->off, c->off + c->len, c->len);
- }
+ } while (size > 0);
}
return 0;
diff --git a/src/rename-logic.py b/src/rename-logic.py
index 9916c96..1544133 100755
--- a/src/rename-logic.py
+++ b/src/rename-logic.py
@@ -33,7 +33,7 @@ def recursive(src, rel_path, dst, dst_should_dir, replace_dir_name):
def fill_dst(src, dst):
- dst_should_dir = isdir(src)
+ dst_should_dir = isdir(src) | isdir(dst)
replace_dir_name = not isdir(dst)
recursive(src, "", dst, dst_should_dir, replace_dir_name)
diff --git a/test/test_e2e.py b/test/test_e2e.py
index 3091255..bc06805 100644
--- a/test/test_e2e.py
+++ b/test/test_e2e.py
@@ -163,7 +163,9 @@ def test_cannot_override_file_with_dir(mscp, src_prefix, dst_prefix):
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
def test_transfer_zero_bytes(mscp, src_prefix, dst_prefix):
src = File("src", size = 0).make()
+ dst = File("dst")
run2ok([mscp, src_prefix + src.path, dst_prefix + "dst"])
+ assert os.path.exists("dst")
src.cleanup()
-
+ dst.cleanup()