[Bug 12036] Multiple --link-dest, --copy-dest, or --compare-dest flags produce incorrect behavior

samba-bugs at samba.org samba-bugs at samba.org
Mon Jul 25 22:53:49 UTC 2016


https://bugzilla.samba.org/show_bug.cgi?id=12036

--- Comment #1 from Chris Kuehl <ckuehl at ocf.berkeley.edu> ---
Looking through the code, this sticks out to me:

    static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
                 char *cmpbuf, stat_x *sxp, int find_exact_for_existing,
                 int itemizing, enum logcode code)
    {
        STRUCT_STAT real_st = sxp->st;
        int best_match = -1;
        int match_level = 0;
        int j = 0;

        do {
            pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
            if (link_stat(cmpbuf, &sxp->st, 0) < 0 ||
!S_ISREG(sxp->st.st_mode))
                continue;
            switch (match_level) {
            case 0:
                best_match = j;
                match_level = 1;
                /* FALL THROUGH */
            case 1:
                if (!unchanged_file(cmpbuf, file, &sxp->st))
                    continue;
                best_match = j;
                match_level = 2;
                /* FALL THROUGH */
            case 2:
                if (!unchanged_attrs(cmpbuf, file, sxp)) {
                    free_stat_x(sxp);
                    continue;
                }
                best_match = j;
                match_level = 3;
                break;
            }
            break;
        } while (basis_dir[++j] != NULL);

It looks to me like on the first iteration of the loop, we match all the way
through to "match_level = 2" with the file from "copy_dest/good", which has the
same content. The mtime doesn't match, though, so we break there.

On the second iteration of the loop, "match_level" is still 2, and we only
compare the attributes with the file from "copy_dest/bad" (never the content).
We then break from the loop and link the wrong file into dest.

I've attached my attempt at a patch to correct this.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.



More information about the rsync mailing list