Do some simple tests with various read-only and set[ug]id files.
[rsync/rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 7a1c3f9..48aa610 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -32,6 +32,7 @@ extern int preserve_uid;
 extern int preserve_gid;
 extern int force_delete;
 extern int recurse;
+extern int keep_dirlinks;
 extern int make_backups;
 extern char *backup_dir;
 extern int inplace;
@@ -98,7 +99,7 @@ int delete_file(char *fname)
                        continue;
                pathjoin(buf, sizeof buf, fname, dname);
                if (verbose > 0)
-                       rprintf(FINFO, "deleting %s\n", buf);
+                       rprintf(FINFO, "deleting %s\n", safe_fname(buf));
                if (delete_file(buf) != 0) {
                        closedir(d);
                        return -1;
@@ -187,7 +188,8 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
                  * destination had the setuid or setgid bits set due
                  * to the side effect of the chown call */
                if (st->st_mode & (S_ISUID | S_ISGID)) {
-                       link_stat(fname, st, 0);
+                       link_stat(fname, st,
+                                 keep_dirlinks && S_ISDIR(st->st_mode));
                }
                updated = 1;
        }
@@ -243,8 +245,7 @@ void finish_transfer(char *fname, char *fnametmp, struct file_struct *file,
        if (inplace) {
                if (verbose > 2)
                        rprintf(FINFO, "finishing %s\n", fname);
-               set_perms(fname, file, NULL, 0);
-               return;
+               goto do_set_perms;
        }
 
        /* move tmp file over real file */
@@ -256,10 +257,10 @@ void finish_transfer(char *fname, char *fnametmp, struct file_struct *file,
                    ret == -2 ? "copy" : "rename",
                    full_fname(fnametmp), fname);
                do_unlink(fnametmp);
-       } else {
-               set_perms(fname, file, NULL,
-                         ok_to_set_time ? 0 : PERMS_SKIP_MTIME);
+               return;
        }
+    do_set_perms:
+       set_perms(fname, file, NULL, ok_to_set_time ? 0 : PERMS_SKIP_MTIME);
 }
 
 const char *who_am_i(void)