Bug 4080 - rsync can't find basis dirs with -n and nonexistent destination
rsync can't find basis dirs with -n and nonexistent destination
Status: CLOSED FIXED
Product: rsync
Classification: Unclassified
Component: core
2.6.9
All All
: P3 normal
: ---
Assigned To: Wayne Davison
Rsync QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-09-04 16:53 UTC by Matt McCutchen
Modified: 2006-10-15 13:26 UTC (History)
0 users

See Also:


Attachments
Test case for this bug (829 bytes, text/plain)
2006-10-08 16:47 UTC, Matt McCutchen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matt McCutchen 2006-09-04 16:53:30 UTC
The man page says that relative basis directory paths are to be relative to the destination directory.  This usually works because the receiving rsync chdirs into the destination directory in get_local_name and then follows the paths verbatim.

However, if --dry-run is on and the destination directory does not exist, the receiver skips the chdir and tries to follow basis directory paths from its original working directory, so it doesn't find the correct basis directories.  The dry run itemizes transfers where a real run might itemize nothing, local creations, or hard links, violating the principle that rsync should produce the same output with and without --dry-run.

As a fix, I propose that, when --dry-run is on and the destination directory does not exist, the receiver should chdir instead into its parent directory.  (The parent has to exist in order for the destination to be created on a real run, so I think it's reasonable to also expect the parent to exist on a dry run.)  Then the receiver should remove an initial ../ from each basis directory path that has one and discard basis directory paths that do not begin with ../ .
Comment 1 Wayne Davison 2006-10-08 16:44:17 UTC
I checked-in some changes that fix this by turning relative paths in the basis_dir[] array into absolute paths based on the destination directory when the destination directory does not yet exist and --dry-run was used.
Comment 2 Matt McCutchen 2006-10-08 16:47:11 UTC
Created attachment 2178 [details]
Test case for this bug

Awesome!  You fixed it!  Perhaps you'd like a test case?
Comment 3 Matt McCutchen 2006-10-09 17:47:58 UTC
This isn't completely fixed.  fix_basis_dirs calls clean_fname, which will remove all x/../ sequences from each joined basis dir path, not just the one straddling the boundary between destination path and original basis dir path.  This might not be correct if x is a symlink.  For example:

$ mkdir zone
$ ln -s . zone/me
$ mkdir src basis
$ touch src/foo
$ rsync -a src/ basis/
$ rsync -n -ai --compare-dest=../../basis/ src/ zone/me/dest/
cd+++++++ ./
>f+++++++ foo
$ rsync -ai --compare-dest=../../basis/ src/ zone/me/dest/
.d..t.... ./

I doubt that a correctly written command line will ever produce incorrect results due to this bug.  However, what could happen is that a user writes "../" steps in the basis dir path expecting them to cancel steps in the destination path, not realizing that some of the steps in the destination path are symlinks.  The user wisely runs rsync in --dry-run mode first and rsync seems to find the basis dir correctly, so she assumes her command is correct and runs rsync for real--and rsync doesn't find the basis dir.

Another question: why does rsync itemize the top-level destination directory as a creation in --dry-run mode but not in real mode?  Maybe this should be a separate bug.
Comment 4 Wayne Davison 2006-10-10 19:28:23 UTC
I changed the function to limit the path cleanup that it will do (only allowing a single ../ to be collapsed).

As for the itemizing of the root dir when doing a copy like this:

rsync -ai dir/ newdir/

I decided that I would like to see the "./" dir being itemized as a new creation, so I added code to make that happen.