diff options
author | Ryo Nakamura <upa@haeena.net> | 2023-08-03 20:26:13 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2023-08-03 20:26:13 +0900 |
commit | ba6f53d25333fed24aa9d602262554080697bdf2 (patch) | |
tree | 63573c4226cd01e15a963c2d970c9f06d6effb99 /src/mscp.c | |
parent | 9f7c135b1515ae297b839f54ea08c1fd16c9521e (diff) |
add glob for source paths
https://github.com/upa/mscp/issues/3
Diffstat (limited to 'src/mscp.c')
-rw-r--r-- | src/mscp.c | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -378,6 +378,8 @@ void *mscp_scan_thread(void *arg) struct path *p; struct src *s; struct stat ss, ds; + glob_t pglob; + int n; m->ret_scan = 0; @@ -418,21 +420,33 @@ void *mscp_scan_thread(void *arg) /* walk a src_path recusively, and resolve path->dst_path for each src */ list_for_each_entry(s, &m->src_list, list) { - if (mscp_stat(s->path, &ss, src_sftp) < 0) { - mscp_set_error("stat: %s", strerrno()); + memset(&pglob, 0, sizeof(pglob)); + if (mscp_glob(s->path, GLOB_NOCHECK, &pglob, src_sftp) < 0) { + mscp_set_error("mscp_glob: %s", strerrno()); goto err_out; } - /* set path specific args */ - a.src_path = s->path; - a.dst_path = m->dst_path; - a.src_path_is_dir = S_ISDIR(ss.st_mode); + for (n = 0; n < pglob.gl_pathc; n++) { + if (mscp_stat(pglob.gl_pathv[n], &ss, src_sftp) < 0) { + mscp_set_error("stat: %s %s", s->path, strerrno()); + goto err_out; + } - INIT_LIST_HEAD(&tmp); - if (walk_src_path(src_sftp, s->path, &tmp, &a) < 0) - goto err_out; + if (!a.dst_path_should_dir && pglob.gl_pathc > 1) + a.dst_path_should_dir = true; /* we have over 1 src */ + + /* set path specific args */ + a.src_path = pglob.gl_pathv[n]; + a.dst_path = m->dst_path; + a.src_path_is_dir = S_ISDIR(ss.st_mode); - list_splice_tail(&tmp, m->path_list.prev); + INIT_LIST_HEAD(&tmp); + if (walk_src_path(src_sftp, pglob.gl_pathv[n], &tmp, &a) < 0) + goto err_out; + + list_splice_tail(&tmp, m->path_list.prev); + } + globfree(&pglob); } mpr_info(m->msg_fp, "walk source path(s) done\n"); |