Add an option, --dir-times, that tells rsync to preserve the modtime of
[rsync/rsync-patches.git] / dir-times.diff
1 --- options.c   6 May 2004 21:08:01 -0000       1.148
2 +++ options.c   13 May 2004 07:11:12 -0000
3 @@ -46,6 +46,7 @@ int preserve_devices = 0;
4  int preserve_uid = 0;
5  int preserve_gid = 0;
6  int preserve_times = 0;
7 +int preserve_dir_times = 0;
8  int update_only = 0;
9  int cvs_exclude = 0;
10  int dry_run = 0;
11 @@ -240,7 +241,8 @@ void usage(enum logcode F)
12    rprintf(F," -o, --owner                 preserve owner (root only)\n");
13    rprintf(F," -g, --group                 preserve group\n");
14    rprintf(F," -D, --devices               preserve devices (root only)\n");
15 -  rprintf(F," -t, --times                 preserve times\n");
16 +  rprintf(F," -t, --times                 preserve times on non-directories\n");
17 +  rprintf(F," -d, --dir-times             preserve times on directories\n");
18    rprintf(F," -S, --sparse                handle sparse files efficiently\n");
19    rprintf(F," -n, --dry-run               show what would have been transferred\n");
20    rprintf(F," -W, --whole-file            copy whole files, no incremental checks\n");
21 @@ -346,6 +348,7 @@ static struct poptOption long_options[] 
22    {"group",           'g', POPT_ARG_NONE,   &preserve_gid, 0, 0, 0 },
23    {"devices",         'D', POPT_ARG_NONE,   &preserve_devices, 0, 0, 0 },
24    {"times",           't', POPT_ARG_NONE,   &preserve_times, 0, 0, 0 },
25 +  {"dir-times",       'd', POPT_ARG_NONE,   &preserve_dir_times, 0, 0, 0 },
26    {"checksum",        'c', POPT_ARG_NONE,   &always_checksum, 0, 0, 0 },
27    {"verbose",         'v', POPT_ARG_NONE,   0,               'v', 0, 0 },
28    {"quiet",           'q', POPT_ARG_NONE,   0,               'q', 0, 0 },
29 @@ -823,6 +826,8 @@ void server_options(char **args,int *arg
30                 argstr[x++] = 'D';
31         if (preserve_times)
32                 argstr[x++] = 't';
33 +       if (preserve_dir_times && am_sender)
34 +               argstr[x++] = 'd';
35         if (preserve_perms)
36                 argstr[x++] = 'p';
37         if (recurse)
38 --- rsync.c     13 May 2004 07:08:25 -0000      1.136
39 +++ rsync.c     13 May 2004 07:11:13 -0000
40 @@ -141,14 +141,16 @@ int set_perms(char *fname,struct file_st
41                 st = &st2;
42         }
43  
44 -       if (!preserve_times || S_ISLNK(st->st_mode))
45 -               flags |= PERMS_SKIP_TIME;
46 +       if (S_ISDIR(st->st_mode)) {
47 +               if (!preserve_dir_times)
48 +                       flags |= PERMS_SKIP_TIME;
49 +       } else {
50 +               if (!preserve_times || S_ISLNK(st->st_mode))
51 +                       flags |= PERMS_SKIP_TIME;
52 +       }
53         if (!(flags & PERMS_SKIP_TIME)
54             && cmp_modtime(st->st_mtime, file->modtime) != 0) {
55 -               /* don't complain about not setting times on directories
56 -                * because some filesystems can't do it */
57 -               if (set_modtime(fname,file->modtime) != 0 &&
58 -                   !S_ISDIR(st->st_mode)) {
59 +               if (set_modtime(fname,file->modtime) != 0) {
60                         rprintf(FERROR, "failed to set times on %s: %s\n",
61                                 full_fname(fname), strerror(errno));
62                         return 0;
63 --- rsync.yo    7 May 2004 00:18:37 -0000       1.169
64 +++ rsync.yo    13 May 2004 07:11:14 -0000
65 @@ -298,7 +298,8 @@ verb(
66   -o, --owner                 preserve owner (root only)
67   -g, --group                 preserve group
68   -D, --devices               preserve devices (root only)
69 - -t, --times                 preserve times
70 + -t, --times                 preserve times on non-directories
71 + -d, --dir-times             preserve times on directories
72   -S, --sparse                handle sparse files efficiently
73   -n, --dry-run               show what would have been transferred
74   -W, --whole-file            copy whole files, no incremental checks
75 @@ -538,13 +539,22 @@ dit(bf(-D, --devices)) This option cause
76  block device information to the remote system to recreate these
77  devices. This option is only available to the super-user.
78  
79 -dit(bf(-t, --times)) This tells rsync to transfer modification times along
80 -with the files and update them on the remote system.  Note that if this
81 +dit(bf(-t, --times)) This tells rsync to preserve modification times of
82 +non-directories transferred to the remote system.  Note that if this
83  option is not used, the optimization that excludes files that have not been
84  modified cannot be effective; in other words, a missing -t or -a will
85  cause the next transfer to behave as if it used -I, and all files will have
86  their checksums compared and show up in log messages even if they haven't
87  changed.
88 +
89 +dit(bf(-d, --dir-times)) This tells rsync to preserve the modification
90 +times of directories transferred to the remote system.  On a modern
91 +rsync, these are left unpreserved by default to avoid causing problems
92 +for NFS.
93 +
94 +Note: when sending files to an older rsync, the --times option will
95 +imply --dir-times (if the option causes an error on the receiving
96 +system, omit it and use --times to preserve all file/directory times).
97  
98  dit(bf(-n, --dry-run)) This tells rsync to not do any file transfers,
99  instead it will just report the actions it would have taken.
100 --- testsuite/chgrp.test        5 Feb 2004 01:37:08 -0000       1.10
101 +++ testsuite/chgrp.test        13 May 2004 07:11:15 -0000
102 @@ -29,7 +29,7 @@ do
103  done
104  sleep 2
105  
106 -checkit "$RSYNC -rtgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
107 +checkit "$RSYNC -rtdgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
108  
109  # The script would have aborted on error, so getting here means we've won.
110  exit 0
111 --- testsuite/chown.test        4 Feb 2004 18:24:41 -0000       1.4
112 +++ testsuite/chown.test        13 May 2004 07:11:15 -0000
113 @@ -31,7 +31,7 @@ chown 5001 "$name2" || test_skipped "Can
114  chgrp 5002 "$name1" || test_skipped "Can't chgrp (probably need root)"
115  chgrp 5003 "$name2" || test_skipped "Can't chgrp (probably need root)"
116  
117 -checkit "$RSYNC -aHvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
118 +checkit "$RSYNC -adHvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
119  
120  # The script would have aborted on error, so getting here means we've won.
121  exit 0
122 --- testsuite/daemon-gzip-download.test 4 Feb 2004 18:24:41 -0000       1.6
123 +++ testsuite/daemon-gzip-download.test 13 May 2004 07:11:15 -0000
124 @@ -27,7 +27,7 @@ RSYNC_CONNECT_PROG="$RSYNC --config=$con
125  export RSYNC_CONNECT_PROG
126  
127  hands_setup
128 -checkit "$RSYNC -avvvvz localhost::test-from/ \"$TO/\"" "$FROM" "$TO"
129 +checkit "$RSYNC -advvvvz localhost::test-from/ \"$TO/\"" "$FROM" "$TO"
130  
131  # The script would have aborted on error, so getting here means we've won.
132  exit 0
133 --- testsuite/daemon-gzip-upload.test   4 Feb 2004 18:24:41 -0000       1.6
134 +++ testsuite/daemon-gzip-upload.test   13 May 2004 07:11:15 -0000
135 @@ -21,7 +21,7 @@ RSYNC_CONNECT_PROG="$RSYNC --config=$con
136  export RSYNC_CONNECT_PROG
137  
138  hands_setup
139 -checkit "$RSYNC -avvvvz \"$FROM/\" localhost::test-to/" "$FROM" "$TO"
140 +checkit "$RSYNC -advvvvz \"$FROM/\" localhost::test-to/" "$FROM" "$TO"
141  
142  # The script would have aborted on error, so getting here means we've won.
143  exit 0
144 --- testsuite/devices.test      9 Apr 2004 00:36:45 -0000       1.7
145 +++ testsuite/devices.test      13 May 2004 07:11:15 -0000
146 @@ -32,7 +32,7 @@ mknod "$fromdir/block" b 42 69 || test_s
147  mknod "$fromdir/block2" b 42 73 || test_skipped "Can't create block device node unless root"
148  mknod "$fromdir/block3" b 105 73 || test_skipped "Can't create block device node unless root"
149  
150 -checkit "$RSYNC -aHvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
151 +checkit "$RSYNC -adHvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
152  
153  # The script would have aborted on error, so getting here means we've won.
154  exit 0
155 --- testsuite/duplicates.test   4 Feb 2004 18:24:41 -0000       1.9
156 +++ testsuite/duplicates.test   13 May 2004 07:11:15 -0000
157 @@ -36,7 +36,7 @@ ln -s "$name1" "$name2" || fail "can't c
158  
159  outfile="$scratchdir/rsync.out"
160  
161 -checkit "$RSYNC -avv \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" \
162 +checkit "$RSYNC -advv \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" \
163      | tee "$outfile"
164  
165  # Make sure each file was only copied once...
166 --- testsuite/exclude.test      14 Apr 2004 20:50:32 -0000      1.5
167 +++ testsuite/exclude.test      13 May 2004 07:11:15 -0000
168 @@ -67,7 +67,7 @@ EOF
169  
170  # Create the chk dir with what we expect to be excluded
171  
172 -checkit "$RSYNC -avv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
173 +checkit "$RSYNC -advv \"$fromdir/\" \"$chkdir/\"" "$fromdir" "$chkdir"
174  
175  sleep 1 # Ensures that the rm commands will tweak the directory times.
176  
177 @@ -79,11 +79,11 @@ rm "$chkdir"/mid/for/foo/extra
178  
179  # Un-tweak the directory times in our first (weak) exclude test (though
180  # it's a good test of the --existing option).
181 -$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
182 +$RSYNC -adv --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
183  
184  # Now, test if rsync excludes the same files.
185  
186 -checkit "$RSYNC -avv --exclude-from=$excl \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
187 +checkit "$RSYNC -advv --exclude-from=$excl \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
188  
189  # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
190  
191 @@ -93,12 +93,12 @@ rm "$chkdir"/bar/down/to/foo/*.junk
192  rm "$chkdir"/bar/down/to/home-cvs-exclude
193  rm "$chkdir"/mid/one-in-one-out
194  
195 -$RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
196 +$RSYNC -adv --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
197  
198  # Now, test if rsync excludes the same files, this time with --cvs-exclude
199  # and --delete-excluded.
200  
201 -checkit "$RSYNC -avvC --delete-excluded --exclude-from=$excl \
202 +checkit "$RSYNC -advvC --delete-excluded --exclude-from=$excl \
203      \"$fromdir/\" \"$todir/\"" "$chkdir" "$todir"
204  
205  # The script would have aborted on error, so getting here means we've won.
206 --- testsuite/hands.test        4 Feb 2004 18:24:41 -0000       1.12
207 +++ testsuite/hands.test        13 May 2004 07:11:15 -0000
208 @@ -11,19 +11,19 @@ hands_setup
209  
210  # Main script starts here
211  
212 -runtest "basic operation" 'checkit "$RSYNC -av ${FROM}/ ${TO}" ${FROM}/ ${TO}'
213 +runtest "basic operation" 'checkit "$RSYNC -adv ${FROM}/ ${TO}" ${FROM}/ ${TO}'
214  
215  ln ${FROM}/filelist ${FROM}/dir
216 -runtest "hard links" 'checkit "$RSYNC -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
217 +runtest "hard links" 'checkit "$RSYNC -advH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
218  
219  rm ${TO}/text
220 -runtest "one file" 'checkit "$RSYNC -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
221 +runtest "one file" 'checkit "$RSYNC -advH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
222  
223  echo "extra line" >> ${TO}/text
224 -runtest "extra data" 'checkit "$RSYNC -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
225 +runtest "extra data" 'checkit "$RSYNC -advH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
226  
227  cp ${FROM}/text ${TO}/ThisShouldGo
228 -runtest " --delete" 'checkit "$RSYNC --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
229 +runtest " --delete" 'checkit "$RSYNC --delete -advH ${FROM}/ ${TO}" ${FROM}/ ${TO}'
230  
231  # The script would have aborted on error, so getting here means we've won.
232  exit 0
233 --- testsuite/hardlinks.test    4 Feb 2004 18:24:41 -0000       1.4
234 +++ testsuite/hardlinks.test    13 May 2004 07:11:15 -0000
235 @@ -31,7 +31,7 @@ ln "$name1" "$name2" || fail "Can't crea
236  ln "$name2" "$name3" || fail "Can't create hardlink"
237  cp "$name2" "$name4" || fail "Can't copy file"
238  
239 -checkit "$RSYNC -aHvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
240 +checkit "$RSYNC -adHvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
241  
242  # The script would have aborted on error, so getting here means we've won.
243  exit 0
244 --- testsuite/longdir.test      4 Feb 2004 18:24:41 -0000       1.9
245 +++ testsuite/longdir.test      13 May 2004 07:11:15 -0000
246 @@ -18,7 +18,7 @@ makepath $LONGDIR || test_skipped "unabl
247  touch $LONGDIR/1 || test_skipped "unable to create files in long directory"
248  date > ${LONGDIR}/1
249  ls -la / > ${LONGDIR}/2
250 -checkit "$RSYNC --delete -avH ${FROM}/ ${TO}" ${FROM}/ ${TO}
251 +checkit "$RSYNC --delete -advH ${FROM}/ ${TO}" ${FROM}/ ${TO}
252  
253  # The script would have aborted on error, so getting here means we've won.
254  exit 0
255 --- testsuite/merge.test        30 Apr 2004 17:24:49 -0000      1.5
256 +++ testsuite/merge.test        13 May 2004 07:11:15 -0000
257 @@ -43,9 +43,9 @@ cp -p "$from2dir"/sub1/uno "$from3dir"/s
258  cp -p "$from3dir"/sub2/subby "$chkdir"/sub2
259  
260  # Get rid of any directory-time differences
261 -$RSYNC -av --existing --include='*/' --exclude='*' "$from1dir/" "$from2dir/" "$from3dir/" "$chkdir/"
262 +$RSYNC -adv --existing --include='*/' --exclude='*' "$from1dir/" "$from2dir/" "$from3dir/" "$chkdir/"
263  
264 -checkit "$RSYNC -aHvv \"$from1dir/\" \"$from2dir/\" \"$from3dir/\" \"$todir/\"" "$chkdir" "$todir"
265 +checkit "$RSYNC -adHvv \"$from1dir/\" \"$from2dir/\" \"$from3dir/\" \"$todir/\"" "$chkdir" "$todir"
266  
267  # The script would have aborted on error, so getting here means we've won.
268  exit 0
269 --- testsuite/ssh-basic.test    19 Feb 2003 16:22:50 -0000      1.6
270 +++ testsuite/ssh-basic.test    13 May 2004 07:11:15 -0000
271 @@ -28,7 +28,7 @@ fi
272  # nothing to do.
273  hands_setup
274  
275 -runtest "ssh: basic test" 'checkit "$RSYNC -avH -e ssh --rsync-path=$RSYNC ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
276 +runtest "ssh: basic test" 'checkit "$RSYNC -advH -e ssh --rsync-path=$RSYNC ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
277  
278  # Added by Steve Bonds Feb 2 2003
279  # I assumed that "F1" was intended to hold a single file for testing if
280 @@ -40,4 +40,4 @@ F1=`ls ${TO} | head -5 | tail -1`
281  
282  mv ${TO}/${F1} ${TO}/ThisShouldGo
283  
284 -runtest "ssh: renamed file" 'checkit "$RSYNC --delete -avH -e ssh --rsync-path=$RSYNC ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
285 +runtest "ssh: renamed file" 'checkit "$RSYNC --delete -advH -e ssh --rsync-path=$RSYNC ${FROM}/ localhost:${TO}" ${FROM}/ ${TO}'
286 --- testsuite/unsafe-links.test 15 Jan 2003 16:14:07 -0000      1.6
287 +++ testsuite/unsafe-links.test 13 May 2004 07:11:15 -0000
288 @@ -35,33 +35,33 @@ ln -s ../../unsafe/unsafefile "from/safe
289  set -x
290  
291  echo "rsync with relative path and just -a";
292 -$RSYNC -avv from/safe/ to
293 +$RSYNC -advv from/safe/ to
294  test_symlink to/links/file1
295  test_symlink to/links/file2
296  test_symlink to/links/unsafefile
297  
298  echo "rsync with relative path and -a --copy-links"
299 -$RSYNC -avv --copy-links from/safe/ to
300 +$RSYNC -advv --copy-links from/safe/ to
301  test_regular to/links/file1
302  test_regular to/links/file2
303  test_regular to/links/unsafefile
304  
305  echo "rsync with relative path and --copy-unsafe-links";
306 -$RSYNC -avv --copy-unsafe-links from/safe/ to
307 +$RSYNC -advv --copy-unsafe-links from/safe/ to
308  test_symlink to/links/file1
309  test_symlink to/links/file2
310  test_regular to/links/unsafefile
311  
312  rm -rf to
313  echo "rsync with relative2 path";
314 -(cd from; $RSYNC -avv --copy-unsafe-links safe/ ../to)
315 +(cd from; $RSYNC -advv --copy-unsafe-links safe/ ../to)
316  test_symlink to/links/file1
317  test_symlink to/links/file2
318  test_regular to/links/unsafefile
319  
320  rm -rf to
321  echo "rsync with absolute path";
322 -$RSYNC -avv --copy-unsafe-links `pwd`/from/safe/ to
323 +$RSYNC -advv --copy-unsafe-links `pwd`/from/safe/ to
324  test_symlink to/links/file1
325  test_symlink to/links/file2
326  test_regular to/links/unsafefile