Fix --remove-source-files sanity check w/--copy-links the right way.
[rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 68ff6b100931e1cf33977bc149060bbef64f16a5..a0b948dc386c7772f3bba9846c310d40013169c1 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2003-2014 Wayne Davison
+ * Copyright (C) 2003-2018 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@ extern int flist_eof;
 extern int file_old_total;
 extern int keep_dirlinks;
 extern int make_backups;
+extern int sanitize_paths;
 extern struct file_list *cur_flist, *first_flist, *dir_flist;
 extern struct chmod_mode_struct *daemon_chmod_modes;
 #ifdef ICONV_OPTION
@@ -364,7 +365,7 @@ int read_ndx_and_attrs(int f_in, int f_out, int *iflag_ptr, uchar *type_ptr,
                }
                /* Send all the data we read for this flist to the generator. */
                start_flist_forward(ndx);
-               flist = recv_file_list(f_in);
+               flist = recv_file_list(f_in, ndx);
                flist->parent_ndx = ndx;
                stop_flist_forward();
        }
@@ -396,6 +397,11 @@ int read_ndx_and_attrs(int f_in, int f_out, int *iflag_ptr, uchar *type_ptr,
        if (iflags & ITEM_XNAME_FOLLOWS) {
                if ((len = read_vstring(f_in, buf, MAXPATHLEN)) < 0)
                        exit_cleanup(RERR_PROTOCOL);
+
+               if (sanitize_paths) {
+                       sanitize_path(buf, buf, "", 0, SP_DEFAULT);
+                       len = strlen(buf);
+               }
        } else {
                *buf = '\0';
                len = -1;
@@ -550,7 +556,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
        if (!(flags & ATTRS_SKIP_MTIME)
         && (sxp->st.st_mtime != file->modtime
 #ifdef ST_MTIME_NSEC
-         || (NSEC_BUMP(file) && (uint32)sxp->st.ST_MTIME_NSEC != F_MOD_NSEC(file))
+         || (flags & ATTRS_SET_NANO && NSEC_BUMP(file) && (uint32)sxp->st.ST_MTIME_NSEC != F_MOD_NSEC(file))
 #endif
          )) {
                int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), sxp->st.st_mode);
@@ -605,7 +611,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
 }
 
 /* This is only called for SIGINT, SIGHUP, and SIGTERM. */
-RETSIGTYPE sig_int(int sig_num)
+void sig_int(int sig_num)
 {
        /* KLUGE: if the user hits Ctrl-C while ssh is prompting
         * for a password, then our cleanup's sending of a SIGUSR1
@@ -659,14 +665,14 @@ int finish_transfer(const char *fname, const char *fnametmp,
        if (make_backups > 0 && overwriting_basis) {
                int ok = make_backup(fname, False);
                if (!ok)
-                       return 1;
+                       exit_cleanup(RERR_FILEIO);
                if (ok == 1 && fnamecmp == fname)
                        fnamecmp = get_backup_name(fname);
        }
 
        /* Change permissions before putting the file into place. */
        set_file_attrs(fnametmp, file, NULL, fnamecmp,
-                      ok_to_set_time ? 0 : ATTRS_SKIP_MTIME);
+                      ok_to_set_time ? ATTRS_SET_NANO : ATTRS_SKIP_MTIME);
 
        /* move tmp file over real file */
        if (DEBUG_GTE(RECV, 1))
@@ -691,7 +697,7 @@ int finish_transfer(const char *fname, const char *fnametmp,
 
   do_set_file_attrs:
        set_file_attrs(fnametmp, file, NULL, fnamecmp,
-                      ok_to_set_time ? 0 : ATTRS_SKIP_MTIME);
+                      ok_to_set_time ? ATTRS_SET_NANO : ATTRS_SKIP_MTIME);
 
        if (temp_copy_name) {
                if (do_rename(fnametmp, fname) < 0) {