Skip to content

Commit ab4b715

Browse files
authored
sender: resolve --files-from entries under a module subdirectory (#1127)
* sender: resolve --files-from entries under a module subdirectory A --files-from pull whose source is a subdirectory of a daemon module (rsync://host/mod/subdir/) looked up every listed file at the module root. A missing file was reported as "file has vanished" and the transfer ended with code 24; a same-named file at the module root was sent in its place. With --remove-source-files, the sent files were then kept with "Skipping sender remove for changed file". The sender opens each file from the module root with secure_relative_open(), rebuilding the path as F_PATHNAME + "/" + f_name, and secure_sender_parent_fd() rebuilds the parent the same way. A --files-from entry has no F_PATHNAME: like any relative pathname it is relative to orig_dir, the transfer's source directory, which here is a module subdirectory. Dropping orig_dir made both look under mod/<entry> instead of mod/subdir/<entry>. Build the module-relative path in one place, module_relative_path(), and prefix a missing or relative F_PATHNAME with orig_dir's module-relative part, as change_pathname() does when it chdirs. orig_dir is no longer static in flist.c so sender.c can read it. Add daemon-files-from-subdir_test.py, which fails without the fix. * sender: keep the --files-from subdirectory fix minimal and test the module filter * sender, testsuite: shorten the orig_subdir() comment and the test
1 parent 96705c2 commit ab4b715

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

‎NEWS.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Changes in this version:
44

5+
### BUG FIXES:
6+
- Fixed a `--files-from` pull from a subdirectory of a daemon module, which
7+
read each listed file from the module root instead. It could send, and with
8+
`--remove-source-files` delete, a same-named file the module's filter
9+
excludes.
10+
511
### ENHANCEMENTS:
612
- Human-readable output now uses dynamic precision to show three significant
713
digits and appends `i` to binary unit suffixes. `--progress` uses the same

‎flist.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ static inline int is_excluded(const char *fname, int is_dir, int filter_level)
585585
static void send_directory(int f, struct file_list *flist,
586586
char *fbuf, int len, int flags);
587587

588-
static const char *pathname, *orig_dir;
588+
static const char *pathname;
589+
const char *orig_dir;
589590
static int pathname_len;
590591

591592
/* Make sure flist can hold at least flist->used + extra entries. */

‎sender.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ extern int inplace;
5353
extern int inplace_partial;
5454
extern int batch_fd;
5555
extern char *module_dir;
56+
extern unsigned int module_dirlen;
57+
extern const char *orig_dir;
5658
extern int module_dirfd;
5759
extern int write_batch;
5860
extern int file_old_total;
@@ -72,6 +74,12 @@ BOOL extra_flist_sending_enabled;
7274
* machine holding the source files.
7375
**/
7476

77+
/* The module subdir (orig_dir) that a relative F_PATHNAME is under, or "" if absolute. */
78+
static const char *orig_subdir(const char *path)
79+
{
80+
return *path == '/' ? "" : orig_dir + module_dirlen;
81+
}
82+
7583
static int secure_sender_parent_fd(struct file_struct *file, const char *fname, const char **bname_p)
7684
{
7785
#ifdef AT_FDCWD
@@ -160,7 +168,7 @@ static int secure_sender_parent_fd(struct file_struct *file, const char *fname,
160168
if (!path)
161169
path = "";
162170
slash = *path ? "/" : "";
163-
slen = snprintf(secure_path, sizeof secure_path, "%s%s%s", path, slash, fname);
171+
slen = snprintf(secure_path, sizeof secure_path, "%s/%s%s%s", orig_subdir(path), path, slash, fname);
164172
if (slen < 0 || slen >= (int)sizeof secure_path) {
165173
errno = ENAMETOOLONG;
166174
return -1;
@@ -661,7 +669,7 @@ void send_files(int f_in, int f_out)
661669
* from F_PATHNAME (path) and f_name (fname). */
662670
char secure_path[MAXPATHLEN];
663671
const char *relp;
664-
int slen = snprintf(secure_path, sizeof secure_path, "%s%s%s", path, slash, fname);
672+
int slen = snprintf(secure_path, sizeof secure_path, "%s/%s%s%s", orig_subdir(path), path, slash, fname);
665673
if (slen >= (int)sizeof secure_path) {
666674
io_error |= IOERR_GENERAL;
667675
rprintf(FERROR_XFER, "path too long: %s%s%s\n", path, slash, fname);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
# --files-from from a module subdir must not send or remove a filter-excluded module-root file.
3+
4+
import shutil
5+
6+
from rsyncfns import (
7+
SCRATCHDIR, assert_exists, assert_not_exists, makepath, run_rsync,
8+
start_test_daemon, test_fail, write_daemon_conf,
9+
)
10+
11+
DAEMON_PORT = 12912
12+
13+
module = SCRATCHDIR / 'module'
14+
listed = module / 'subdir' / 'file.txt'
15+
excluded = module / 'file.txt'
16+
dst = SCRATCHDIR / 'dst'
17+
makepath(listed.parent)
18+
listed.write_text("listed\n")
19+
excluded.write_text("hidden\n")
20+
shutil.copystat(listed, excluded)
21+
listing = SCRATCHDIR / 'files-from.list'
22+
listing.write_text("file.txt\n")
23+
24+
conf = write_daemon_conf([
25+
('mod', {'path': str(module), 'read only': 'no', 'filter': '+ /subdir/*** - *'}),
26+
])
27+
url = start_test_daemon(conf, DAEMON_PORT)
28+
29+
run_rsync('-rt', '--remove-source-files', f'--files-from={listing}', f'{url}mod/subdir/', f'{dst}/')
30+
if (dst / 'file.txt').read_text() != "listed\n":
31+
test_fail("the pull sent the excluded module-root file")
32+
assert_not_exists(listed, label="--remove-source-files")
33+
assert_exists(excluded, label="excluded module-root file")

0 commit comments

Comments
 (0)