Updated the opening comments to mention how to apply the patch
[rsync-patches.git] / date-only.diff
1 Jeremy Bornstein wrote:
2
3 I recently had the need to transfer files only with different mod
4 dates (and to *not* transfer them based on file size differences).
5 This is because I'm backing up files remotely on an untrusted machine,
6 so I'm encrypting them with gpg before transfer.  I discovered that
7 rsync didn't already have a --date-only flag, so I added one and am
8 enclosing the diffs in case you (as I hope) decide to include this
9 option in future releases.
10
11 To use this patch, run these commands for a successful build:
12
13     patch -p1 <patches/date-only.diff
14     ./configure                                 (optional if already run)
15     make
16
17 --- old/generator.c
18 +++ new/generator.c
19 @@ -60,6 +60,7 @@ extern int append_mode;
20  extern int make_backups;
21  extern int csum_length;
22  extern int ignore_times;
23 +extern int date_only;
24  extern int size_only;
25  extern OFF_T max_size;
26  extern OFF_T min_size;
27 @@ -378,6 +379,8 @@ void itemize(struct file_struct *file, i
28  /* Perform our quick-check heuristic for determining if a file is unchanged. */
29  int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
30  {
31 +       if (date_only)
32 +               return cmp_time(st->st_mtime, file->modtime) == 0;
33         if (st->st_size != file->length)
34                 return 0;
35  
36 --- old/options.c
37 +++ new/options.c
38 @@ -99,6 +99,7 @@ int keep_partial = 0;
39  int safe_symlinks = 0;
40  int copy_unsafe_links = 0;
41  int size_only = 0;
42 +int date_only = 0;
43  int daemon_bwlimit = 0;
44  int bwlimit = 0;
45  int fuzzy_basis = 0;
46 @@ -343,6 +344,7 @@ void usage(enum logcode F)
47    rprintf(F,"     --timeout=TIME          set I/O timeout in seconds\n");
48    rprintf(F," -I, --ignore-times          don't skip files that match in size and mod-time\n");
49    rprintf(F,"     --size-only             skip files that match in size\n");
50 +  rprintf(F,"     --date-only             skip files that match in mod-time\n");
51    rprintf(F,"     --modify-window=NUM     compare mod-times with reduced accuracy\n");
52    rprintf(F," -T, --temp-dir=DIR          create temporary files in directory DIR\n");
53    rprintf(F," -y, --fuzzy                 find similar file for basis if no dest file\n");
54 @@ -463,6 +465,7 @@ static struct poptOption long_options[] 
55    {"chmod",            0,  POPT_ARG_STRING, 0, OPT_CHMOD, 0, 0 },
56    {"ignore-times",    'I', POPT_ARG_NONE,   &ignore_times, 0, 0, 0 },
57    {"size-only",        0,  POPT_ARG_NONE,   &size_only, 0, 0, 0 },
58 +  {"date-only",        0,  POPT_ARG_NONE,   &date_only, 0, 0, 0 },
59    {"one-file-system", 'x', POPT_ARG_NONE,   0, 'x', 0, 0 },
60    {"update",          'u', POPT_ARG_NONE,   &update_only, 0, 0, 0 },
61    {"existing",         0,  POPT_ARG_NONE,   &ignore_non_existing, 0, 0, 0 },
62 @@ -1676,6 +1679,9 @@ void server_options(char **args,int *arg
63                         args[ac++] = "--size-only";
64         }
65  
66 +       if (date_only)
67 +               args[ac++] = "--date-only";
68 +
69         if (modify_window_set) {
70                 if (asprintf(&arg, "--modify-window=%d", modify_window) < 0)
71                         goto oom;
72 --- old/rsync.yo
73 +++ new/rsync.yo
74 @@ -360,6 +360,7 @@ to the detailed description below for a 
75       --timeout=TIME          set I/O timeout in seconds
76   -I, --ignore-times          don't skip files that match size and time
77       --size-only             skip files that match in size
78 +     --date-only             skip files that match in mod-time
79       --modify-window=NUM     compare mod-times with reduced accuracy
80   -T, --temp-dir=DIR          create temporary files in directory DIR
81   -y, --fuzzy                 find similar file for basis if no dest file
82 @@ -477,6 +478,12 @@ regardless of timestamp. This is useful 
83  after using another mirroring system which may not preserve timestamps
84  exactly.
85  
86 +dit(bf(--date-only)) Normally rsync will skip any files that are
87 +already the same size and have the same modification time-stamp. With the
88 +--date-only option, files will be skipped if they have the same
89 +timestamp, regardless of size. This may be useful when the remote
90 +files have passed through a size-changing filter, e.g. for encryption.
91 +
92  dit(bf(--modify-window)) When comparing two timestamps, rsync treats the
93  timestamps as being equal if they differ by no more than the modify-window
94  value.  This is normally 0 (for an exact match), but you may find it useful