mirror of
https://github.com/upa/mscp.git
synced 2026-05-13 22:07:29 +08:00
create file at the remote although file size is 0
This commit is contained in:
21
src/file.c
21
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,
|
int file_fill(sftp_session sftp, struct list_head *file_list, char **src_array, int cnt,
|
||||||
char *dst)
|
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;
|
char *dst_path, *src_path;
|
||||||
int n, ret;
|
int n, ret;
|
||||||
|
|
||||||
dst_path = file_find_path(dst);
|
dst_path = file_find_path(dst);
|
||||||
dst_path = *dst_path == '\0' ? "." : dst_path;
|
dst_path = *dst_path == '\0' ? "." : dst_path;
|
||||||
dst_is_remote = file_find_hostname(dst) ? true : false;
|
dst_is_remote = file_find_hostname(dst) ? true : false;
|
||||||
|
|
||||||
if (file_is_directory(dst_path, dst_is_remote ? sftp : NULL, false) > 0)
|
if (file_is_directory(dst_path, dst_is_remote ? sftp : NULL, false) > 0)
|
||||||
dst_dir_no_exist = false;
|
dst_is_dir = true;
|
||||||
else
|
else
|
||||||
dst_dir_no_exist = true;
|
dst_is_dir = false;
|
||||||
|
dst_dir_no_exist = !dst_is_dir;
|
||||||
|
|
||||||
for (n = 0; n < cnt; n++) {
|
for (n = 0; n < cnt; n++) {
|
||||||
src_path = file_find_path(src_array[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;
|
dst_should_dir = false;
|
||||||
|
|
||||||
ret = file_fill_recursive(file_list, dst_is_remote, sftp,
|
ret = file_fill_recursive(file_list, dst_is_remote, sftp,
|
||||||
src_path, "",
|
src_path, "", dst_path,
|
||||||
dst_path, dst_should_dir, dst_dir_no_exist);
|
dst_should_dir | dst_is_dir, dst_dir_no_exist);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
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);
|
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);
|
c = chunk_alloc(f);
|
||||||
if (!c)
|
if (!c)
|
||||||
return -1;
|
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);
|
list_add_tail(&c->list, chunk_list);
|
||||||
pprint4("chunk %s 0x%010lx-0x%010lx %luB\n",
|
pprint4("chunk %s 0x%010lx-0x%010lx %luB\n",
|
||||||
c->f->src_path, c->off, c->off + c->len, c->len);
|
c->f->src_path, c->off, c->off + c->len, c->len);
|
||||||
}
|
} while (size > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def recursive(src, rel_path, dst, dst_should_dir, replace_dir_name):
|
|||||||
|
|
||||||
|
|
||||||
def fill_dst(src, dst):
|
def fill_dst(src, dst):
|
||||||
dst_should_dir = isdir(src)
|
dst_should_dir = isdir(src) | isdir(dst)
|
||||||
replace_dir_name = not isdir(dst)
|
replace_dir_name = not isdir(dst)
|
||||||
recursive(src, "", dst, dst_should_dir, replace_dir_name)
|
recursive(src, "", dst, dst_should_dir, replace_dir_name)
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||||
def test_transfer_zero_bytes(mscp, src_prefix, dst_prefix):
|
def test_transfer_zero_bytes(mscp, src_prefix, dst_prefix):
|
||||||
src = File("src", size = 0).make()
|
src = File("src", size = 0).make()
|
||||||
|
dst = File("dst")
|
||||||
run2ok([mscp, src_prefix + src.path, dst_prefix + "dst"])
|
run2ok([mscp, src_prefix + src.path, dst_prefix + "dst"])
|
||||||
|
assert os.path.exists("dst")
|
||||||
src.cleanup()
|
src.cleanup()
|
||||||
|
dst.cleanup()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user