If the user specified --relative and a source dir with a trailing
[rsync/rsync.git] / generator.c
index 3bb3749..262ffe2 100644 (file)
@@ -249,19 +249,24 @@ static void delete_in_dir(struct file_list *flist, char *fbuf,
        if (link_stat(fbuf, &st, keep_dirlinks) < 0)
                return;
 
-       if (one_file_system && file->flags & FLAG_TOP_DIR)
-               filesystem_dev = st.st_dev;
+       if (one_file_system) {
+               if (file->flags & FLAG_TOP_DIR)
+                       filesystem_dev = st.st_dev;
+               else if (filesystem_dev != st.st_dev)
+                       return;
+       }
 
        dirlist = get_dirlist(fbuf, dlen, 0);
 
        /* If an item in dirlist is not found in flist, delete it
         * from the filesystem. */
        for (i = dirlist->count; i--; ) {
-               if (!dirlist->files[i]->basename)
+               struct file_struct *fp = dirlist->files[i];
+               if (!fp->basename)
                        continue;
-               if (flist_find(flist, dirlist->files[i]) < 0) {
-                       int mode = dirlist->files[i]->mode;
-                       f_name_to(dirlist->files[i], delbuf);
+               if (flist_find(flist, fp) < 0) {
+                       int mode = fp->mode;
+                       f_name_to(fp, delbuf);
                        if (delete_item(delbuf, mode, DEL_FORCE_RECURSE) < 0)
                                break;
                }
@@ -914,8 +919,15 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                                if (hard_link_one(file, ndx, fname, -1, &st,
                                                  fnamecmpbuf, 1,
                                                  itemizing && verbose > 1,
-                                                 code) == 0)
+                                                 code) == 0) {
+                                       if (preserve_hard_links
+                                           && file->link_u.links) {
+                                               hard_link_cluster(file, ndx,
+                                                                 itemizing,
+                                                                 code);
+                                       }
                                        return;
+                               }
                                match_level = 2;
                        }
 #endif