Tweaked a comment.
[rsync/rsync.git] / generator.c
index 97395a7..cccd1ec 100644 (file)
@@ -45,6 +45,7 @@ extern int preserve_uid;
 extern int preserve_gid;
 extern int preserve_times;
 extern int omit_dir_times;
+extern int delete_mode;
 extern int delete_before;
 extern int delete_during;
 extern int delete_after;
@@ -346,10 +347,9 @@ void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
                        iflags |= ITEM_REPORT_SIZE;
                if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time
                     && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
-                   || (keep_time && cmp_modtime(file->modtime, st->st_mtime) != 0))
+                   || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
                        iflags |= ITEM_REPORT_TIME;
-               if (preserve_perms
-                && (file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
+               if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
                        iflags |= ITEM_REPORT_PERMS;
                if (preserve_uid && am_root && file->uid != st->st_uid)
                        iflags |= ITEM_REPORT_OWNER;
@@ -396,7 +396,7 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
        if (ignore_times)
                return 0;
 
-       return cmp_modtime(st->st_mtime, file->modtime) == 0;
+       return cmp_time(st->st_mtime, file->modtime) == 0;
 }
 
 
@@ -556,7 +556,7 @@ static int find_fuzzy(struct file_struct *file, struct file_list *dirlist)
                name = fp->basename;
 
                if (fp->length == file->length
-                   && cmp_modtime(fp->modtime, file->modtime) == 0) {
+                   && cmp_time(fp->modtime, file->modtime) == 0) {
                        if (verbose > 4) {
                                rprintf(FINFO,
                                        "fuzzy size/modtime match for %s\n",
@@ -632,7 +632,7 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
                        if (!unchanged_attrs(file, stp))
                                continue;
                        if ((always_checksum || ignore_times)
-                        && cmp_modtime(stp->st_mtime, file->modtime))
+                        && cmp_time(stp->st_mtime, file->modtime))
                                continue;
                        best_match = j;
                        match_level = 3;
@@ -780,7 +780,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
        char *fnamecmp, *partialptr, *backupptr = NULL;
        char fnamecmpbuf[MAXPATHLEN];
        uchar fnamecmp_type;
-       int del_opts = DEL_TERSE | (delete_after ? DEL_FORCE_RECURSE : 0);
+       int del_opts = DEL_TERSE | (delete_mode ? DEL_FORCE_RECURSE : 0);
 
        if (list_only)
                return;
@@ -854,13 +854,12 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                return;
        }
 
-       if (statret == 0 && !preserve_perms
-           && S_ISDIR(st.st_mode) == S_ISDIR(file->mode)) {
-               /* if the file exists already and we aren't perserving
-                * permissions then act as though the remote end sent
-                * us the file permissions we already have */
-               file->mode = (file->mode & ~CHMOD_BITS)
-                          | (st.st_mode & CHMOD_BITS);
+       /* If we're not preserving permissions, change the file-list's
+        * mode based on the local permissions and some heuristics. */
+       if (!preserve_perms) {
+               int exists = statret == 0
+                         && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
+               file->mode = dest_mode(file->mode, st.st_mode, exists);
        }
 
        if (S_ISDIR(file->mode)) {
@@ -1074,7 +1073,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
        }
 
        if (update_only && statret == 0
-           && cmp_modtime(st.st_mtime, file->modtime) > 0) {
+           && cmp_time(st.st_mtime, file->modtime) > 0) {
                if (verbose > 1)
                        rprintf(FINFO, "%s is newer\n", fname);
                return;