mirror of
https://github.com/upa/mscp.git
synced 2026-02-04 03:24:58 +08:00
fix wrong dst path for source path under '/'
When a source file path is /FILE, its dest path would be dst/ILE. This commit fixes this issue (#8).
This commit is contained in:
16
src/path.c
16
src/path.c
@@ -106,10 +106,18 @@ static int resolve_dst_path(const char *src_file_path, char *dst_file_path,
|
|||||||
mscp_set_error("dirname: %s", strerrno());
|
mscp_set_error("dirname: %s", strerrno());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (strlen(prefix) == 1 && prefix[0] == '.')
|
|
||||||
offset = 0;
|
offset = strlen(prefix) + 1;
|
||||||
else
|
if (strlen(prefix) == 1) { /* corner cases */
|
||||||
offset = strlen(prefix) + 1;
|
switch (prefix[0]) {
|
||||||
|
case '.':
|
||||||
|
offset = 0;
|
||||||
|
break;
|
||||||
|
case '/':
|
||||||
|
offset = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!a->src_path_is_dir && !a->dst_path_is_dir) {
|
if (!a->src_path_is_dir && !a->dst_path_is_dir) {
|
||||||
/* src path is file. dst path is (1) file, or (2) does not exist.
|
/* src path is file. dst path is (1) file, or (2) does not exist.
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ def test_copy_file_under_root_to_dir(mscp, src_prefix, dst_prefix):
|
|||||||
dst_prefix + os.path.dirname(dst.path)])
|
dst_prefix + os.path.dirname(dst.path)])
|
||||||
assert check_same_md5sum(src, dst)
|
assert check_same_md5sum(src, dst)
|
||||||
src.cleanup()
|
src.cleanup()
|
||||||
dst.cleanup()
|
dst.cleanup(preserve_dir = True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ class File():
|
|||||||
with open(self.path, "wb") as f:
|
with open(self.path, "wb") as f:
|
||||||
f.write(os.urandom(self.size))
|
f.write(os.urandom(self.size))
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self, preserve_dir = False):
|
||||||
os.remove(self.path)
|
os.remove(self.path)
|
||||||
|
if preserve_dir:
|
||||||
|
return
|
||||||
tmp = os.path.dirname(self.path)
|
tmp = os.path.dirname(self.path)
|
||||||
while tmp and not tmp in [".", "/"]:
|
while tmp and not tmp in [".", "/"]:
|
||||||
if len(os.listdir(tmp)) == 0:
|
if len(os.listdir(tmp)) == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user