diff options
author | Ryo Nakamura <upa@haeena.net> | 2022-11-05 19:13:53 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2022-11-05 19:13:53 +0900 |
commit | 6e6e5066c7ad83ad2daf8f8ccbe7231211e41c97 (patch) | |
tree | 808f708dc4716ee55eb65ba5a9d47c084e59a46f /src | |
parent | 24126c927d22d2baccb920adf8ebe3ec5a7283a3 (diff) |
create file at the remote although file size is 0
Diffstat (limited to 'src')
-rw-r--r-- | src/file.c | 21 | ||||
-rwxr-xr-x | src/rename-logic.py | 2 |
2 files changed, 14 insertions, 9 deletions
@@ -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) |