John E. Malmberg convinced me to standardize on #ifs for defined
[rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index acb260cc97424461ce2d40ae1f5c3dbc53a0558e..0245c0b3b9fd3af187fcf1efdb3a19c802eb8c35 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -27,6 +27,7 @@ extern int dry_run;
 extern int preserve_times;
 extern int omit_dir_times;
 extern int am_root;
+extern int am_server;
 extern int am_sender;
 extern int am_generator;
 extern int preserve_uid;
@@ -122,9 +123,10 @@ int delete_file(char *fname, int flags)
                else
                        flags &= ~DEL_DIR;
 
-               if (verbose)
+               if (verbose) {
                        rprintf(FINFO, "deleting %s%s\n", safe_fname(buf),
                                flags & DEL_DIR ? "/" : "");
+               }
                if (delete_file(buf, flags) != 0) {
                        closedir(d);
                        return -1;
@@ -183,7 +185,7 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
        change_uid = am_root && preserve_uid && st->st_uid != file->uid;
        change_gid = preserve_gid && file->gid != GID_NONE
                && st->st_gid != file->gid;
-#if !HAVE_LCHOWN && !CHOWN_MODIFIES_SYMLINK
+#if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
        if (S_ISLNK(st->st_mode))
                ;
        else
@@ -192,13 +194,15 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
                if (verbose > 2) {
                        if (change_uid) {
                                rprintf(FINFO,
-                                   "set uid of %s from %ld to %ld\n",
-                                   fname, (long)st->st_uid, (long)file->uid);
+                                       "set uid of %s from %ld to %ld\n",
+                                       safe_fname(fname),
+                                       (long)st->st_uid, (long)file->uid);
                        }
                        if (change_gid) {
                                rprintf(FINFO,
-                                   "set gid of %s from %ld to %ld\n",
-                                   fname, (long)st->st_gid, (long)file->gid);
+                                       "set gid of %s from %ld to %ld\n",
+                                       safe_fname(fname),
+                                       (long)st->st_gid, (long)file->gid);
                        }
                }
                if (do_lchown(fname,
@@ -221,7 +225,7 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
                updated = 1;
        }
 
-#if HAVE_CHMOD
+#ifdef HAVE_CHMOD
        if (!S_ISLNK(st->st_mode)) {
                if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
                        updated = 1;
@@ -236,9 +240,9 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
 
        if (verbose > 1 && flags & PERMS_REPORT) {
                if (updated)
-                       rprintf(FINFO,"%s\n",fname);
+                       rprintf(FINFO, "%s\n", safe_fname(fname));
                else
-                       rprintf(FINFO,"%s is uptodate\n",fname);
+                       rprintf(FINFO, "%s is uptodate\n", safe_fname(fname));
        }
        return updated;
 }
@@ -268,7 +272,7 @@ void finish_transfer(char *fname, char *fnametmp, struct file_struct *file,
 
        if (inplace) {
                if (verbose > 2)
-                       rprintf(FINFO, "finishing %s\n", fname);
+                       rprintf(FINFO, "finishing %s\n", safe_fname(fname));
                goto do_set_perms;
        }
 
@@ -279,13 +283,15 @@ void finish_transfer(char *fname, char *fnametmp, struct file_struct *file,
        set_perms(fnametmp, file, NULL, ok_to_set_time ? 0 : PERMS_SKIP_MTIME);
 
        /* move tmp file over real file */
-       if (verbose > 2)
-               rprintf(FINFO, "renaming %s to %s\n", fnametmp, fname);
+       if (verbose > 2) {
+               rprintf(FINFO, "renaming %s to %s\n",
+                       safe_fname(fnametmp), safe_fname(fname));
+       }
        ret = robust_rename(fnametmp, fname, file->mode & INITACCESSPERMS);
        if (ret < 0) {
                rsyserr(FERROR, errno, "%s %s -> \"%s\"",
                    ret == -2 ? "copy" : "rename",
-                   full_fname(fnametmp), fname);
+                   full_fname(fnametmp), safe_fname(fname));
                do_unlink(fnametmp);
                return;
        }
@@ -299,5 +305,7 @@ void finish_transfer(char *fname, char *fnametmp, struct file_struct *file,
 
 const char *who_am_i(void)
 {
+       if (am_sender < 0)
+               return am_server ? "server" : "client";
        return am_sender ? "sender" : am_generator ? "generator" : "receiver";
 }