summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2023-02-26 23:42:25 +0900
committerRyo Nakamura <upa@haeena.net>2023-02-26 23:42:25 +0900
commitc649742b3eec44d47b887cb8b1deb336ae915dd1 (patch)
tree0fa9f79632e586ef7fee4e5e7d76eb4f3bb5097f /src/path.c
parent700d64b375470de42589ea66baabeee289cb66f2 (diff)
fix dst path resolve
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/path.c b/src/path.c
index dc6cac3..1d6e708 100644
--- a/src/path.c
+++ b/src/path.c
@@ -104,7 +104,8 @@ int walk_src_path(sftp_session src_sftp, const char *src_path,
static int src2dst_path(const char *src_path, const char *src_file_path,
const char *dst_path, char *dst_file_path, size_t len,
- bool src_path_is_dir, bool dst_path_is_dir)
+ bool src_path_is_dir, bool dst_path_is_dir,
+ bool dst_path_should_dir)
{
char copy[PATH_MAX];
char *prefix;
@@ -121,10 +122,16 @@ static int src2dst_path(const char *src_path, const char *src_file_path,
else
offset = strlen(prefix) + 1;
-
- /* both are file */
- if (!src_path_is_dir && !dst_path_is_dir)
- strncpy(dst_file_path, dst_path, len);
+ if (!src_path_is_dir && !dst_path_is_dir) {
+ /* src path is file. dst path is (1) file, or (2) does not exist.
+ * In the second case, we need to put src under the dst.
+ */
+ if (dst_path_should_dir)
+ snprintf(dst_file_path, len, "%s/%s",
+ dst_path, src_path + offset);
+ else
+ strncpy(dst_file_path, dst_path, len);
+ }
/* src is file, and dst is dir */
if (!src_path_is_dir && dst_path_is_dir)
@@ -145,13 +152,15 @@ static int src2dst_path(const char *src_path, const char *src_file_path,
}
int resolve_dst_path(const char *src_path, const char *dst_path,
- struct list_head *path_list, bool src_is_dir, bool dst_is_dir)
+ struct list_head *path_list, bool src_path_is_dir,
+ bool dst_path_is_dir, bool dst_path_should_dir)
{
struct path *p;
list_for_each_entry(p, path_list, list) {
if (src2dst_path(src_path, p->path, dst_path, p->dst_path, PATH_MAX,
- src_is_dir, dst_is_dir) < 0)
+ src_path_is_dir, dst_path_is_dir,
+ dst_path_should_dir) < 0)
return -1;
}