1 --- backup.c 13 Mar 2004 20:18:03 -0000 1.28
2 +++ backup.c 20 Apr 2004 23:44:16 -0000
3 @@ -101,7 +101,7 @@ static int make_bak_dir(char *fullpath)
4 "make_bak_dir stat %s failed: %s\n",
5 full_fname(rel), strerror(errno));
7 - set_modtime(fullpath, st.st_mtime);
8 + set_times(fullpath, st.st_mtime, time(NULL));
9 do_lchown(fullpath, st.st_uid, st.st_gid);
10 do_chmod(fullpath, st.st_mode);
12 --- batch.c 6 Mar 2004 07:45:52 -0000 1.31
13 +++ batch.c 20 Apr 2004 23:44:16 -0000
14 @@ -342,6 +342,8 @@ void show_flist(int index, struct file_s
15 rprintf(FINFO, "flist->flags=%#x\n", fptr[i]->flags);
16 rprintf(FINFO, "flist->modtime=%#lx\n",
17 (long unsigned) fptr[i]->modtime);
18 + rprintf(FINFO, "flist->atime=%#lx\n",
19 + (long unsigned) fptr[i]->atime);
20 rprintf(FINFO, "flist->length=%.0f\n",
21 (double) fptr[i]->length);
22 rprintf(FINFO, "flist->mode=%#o\n", (int) fptr[i]->mode);
23 --- flist.c 17 Apr 2004 17:14:12 -0000 1.214
24 +++ flist.c 20 Apr 2004 23:44:17 -0000
25 @@ -58,6 +58,7 @@ extern int relative_paths;
26 extern int implied_dirs;
27 extern int copy_links;
28 extern int copy_unsafe_links;
29 +extern int copy_atimes;
30 extern int protocol_version;
31 extern int sanitize_paths;
33 @@ -140,16 +141,16 @@ static void list_file_entry(struct file_
36 if (preserve_links && S_ISLNK(f->mode)) {
37 - rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
38 + rprintf(FINFO, "%s %11.0f %s %s %s -> %s\n",
40 (double) f->length, timestring(f->modtime),
41 - f_name(f), f->u.link);
42 + timestring(f->atime), f_name(f), f->u.link);
45 - rprintf(FINFO, "%s %11.0f %s %s\n",
46 + rprintf(FINFO, "%s %11.0f %s %s %s\n",
48 (double) f->length, timestring(f->modtime),
50 + timestring(f->atime), f_name(f));
54 @@ -326,6 +327,7 @@ void send_file_entry(struct file_struct
57 static time_t modtime;
58 + static time_t atime;
62 @@ -341,7 +343,7 @@ void send_file_entry(struct file_struct
66 - modtime = 0, mode = 0;
67 + modtime = 0, atime = 0, mode = 0;
68 dev = 0, rdev = makedev(0, 0);
71 @@ -390,6 +392,12 @@ void send_file_entry(struct file_struct
72 flags |= XMIT_SAME_TIME;
74 modtime = file->modtime;
75 + if (copy_atimes && !S_ISDIR(mode)) {
76 + if (file->atime == atime)
77 + flags |= XMIT_SAME_ATIME;
79 + atime = file->atime;
82 #if SUPPORT_HARD_LINKS
83 if (file->link_u.idev) {
84 @@ -445,6 +453,8 @@ void send_file_entry(struct file_struct
85 write_int(f, modtime);
86 if (!(flags & XMIT_SAME_MODE))
87 write_int(f, to_wire_mode(mode));
88 + if (copy_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
89 + write_int(f, atime);
90 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
93 @@ -518,6 +528,7 @@ void receive_file_entry(struct file_stru
94 struct file_list *flist, int f)
96 static time_t modtime;
97 + static time_t atime;
101 @@ -534,7 +545,7 @@ void receive_file_entry(struct file_stru
102 struct file_struct *file;
105 - modtime = 0, mode = 0;
106 + modtime = 0, atime = 0, mode = 0;
107 dev = 0, rdev = makedev(0, 0);
110 @@ -588,6 +599,8 @@ void receive_file_entry(struct file_stru
111 modtime = (time_t)read_int(f);
112 if (!(flags & XMIT_SAME_MODE))
113 mode = from_wire_mode(read_int(f));
114 + if (copy_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
115 + atime = (time_t)read_int(f);
117 if (preserve_uid && !(flags & XMIT_SAME_UID))
118 uid = (uid_t)read_int(f);
119 @@ -638,6 +651,7 @@ void receive_file_entry(struct file_stru
121 file->flags = flags & XMIT_TOP_DIR ? FLAG_TOP_DIR : 0;
122 file->modtime = modtime;
123 + file->atime = atime;
124 file->length = file_length;
127 @@ -852,6 +866,7 @@ skip_excludes:
130 file->modtime = st.st_mtime;
131 + file->atime = st.st_atime;
132 file->length = st.st_size;
133 file->mode = st.st_mode;
134 file->uid = st.st_uid;
135 --- generator.c 15 Apr 2004 16:55:23 -0000 1.79
136 +++ generator.c 20 Apr 2004 23:44:17 -0000
137 @@ -97,7 +97,7 @@ static int skip_file(char *fname, struct
141 - return (cmp_modtime(st->st_mtime,file->modtime) == 0);
142 + return cmp_time(st->st_mtime,file->modtime) == 0;
146 @@ -464,7 +464,7 @@ void recv_generator(char *fname, struct
150 - if (update_only && cmp_modtime(st.st_mtime,file->modtime)>0 && fnamecmp == fname) {
151 + if (update_only && cmp_time(st.st_mtime,file->modtime)>0 && fnamecmp == fname) {
153 rprintf(FINFO,"%s is newer\n",fname);
155 --- options.c 17 Apr 2004 17:07:23 -0000 1.147
156 +++ options.c 20 Apr 2004 23:44:17 -0000
157 @@ -46,6 +46,7 @@ int preserve_devices = 0;
158 int preserve_uid = 0;
159 int preserve_gid = 0;
160 int preserve_times = 0;
161 +int copy_atimes = 0;
165 @@ -241,6 +242,7 @@ void usage(enum logcode F)
166 rprintf(F," -g, --group preserve group\n");
167 rprintf(F," -D, --devices preserve devices (root only)\n");
168 rprintf(F," -t, --times preserve times\n");
169 + rprintf(F," -A, --copy-atimes copy access times\n");
170 rprintf(F," -S, --sparse handle sparse files efficiently\n");
171 rprintf(F," -n, --dry-run show what would have been transferred\n");
172 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
173 @@ -346,6 +348,7 @@ static struct poptOption long_options[]
174 {"group", 'g', POPT_ARG_NONE, &preserve_gid, 0, 0, 0 },
175 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
176 {"times", 't', POPT_ARG_NONE, &preserve_times, 0, 0, 0 },
177 + {"copy-atimes", 'A', POPT_ARG_NONE, ©_atimes, 0, 0, 0 },
178 {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 },
179 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
180 {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
181 @@ -823,6 +826,8 @@ void server_options(char **args,int *arg
190 --- proto.h 14 Apr 2004 23:33:30 -0000 1.188
191 +++ proto.h 20 Apr 2004 23:44:17 -0000
192 @@ -243,7 +243,7 @@ int fd_pair(int fd[2]);
193 void print_child_argv(char **cmd);
194 void out_of_memory(char *str);
195 void overflow(char *str);
196 -int set_modtime(char *fname, time_t modtime);
197 +int set_times(char *fname, time_t modtime, time_t atime);
198 int create_directory_path(char *fname, int base_umask);
199 int copy_file(char *source, char *dest, mode_t mode);
200 int robust_unlink(char *fname);
201 @@ -267,7 +267,7 @@ int u_strcmp(const char *cs1, const char
202 int unsafe_symlink(const char *dest, const char *src);
203 char *timestring(time_t t);
205 -int cmp_modtime(time_t file1, time_t file2);
206 +int cmp_time(time_t file1, time_t file2);
207 int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
208 void *_new_array(unsigned int size, unsigned long num);
209 void *_realloc_array(void *ptr, unsigned int size, unsigned long num);
210 --- rsync.c 23 Mar 2004 16:16:15 -0000 1.135
211 +++ rsync.c 20 Apr 2004 23:44:17 -0000
215 extern int preserve_times;
216 +extern int copy_atimes;
218 extern int am_server;
219 extern int am_sender;
220 @@ -140,17 +141,28 @@ int set_perms(char *fname,struct file_st
224 - if (preserve_times && !S_ISLNK(st->st_mode) &&
225 - cmp_modtime(st->st_mtime, file->modtime) != 0) {
226 + if (!S_ISLNK(st->st_mode) && (preserve_times || copy_atimes)) {
227 + time_t atime, mtime;
229 + if (copy_atimes && !S_ISDIR(st->st_mode)
230 + && cmp_time(st->st_atime, file->atime) != 0) {
231 + atime = file->atime;
234 + atime = st->st_atime;
235 + if (preserve_times && cmp_time(st->st_mtime, file->modtime) != 0) {
236 + mtime = file->modtime;
239 + mtime = st->st_mtime;
240 /* don't complain about not setting times on directories
241 * because some filesystems can't do it */
242 - if (set_modtime(fname,file->modtime) != 0 &&
243 + if (updated && set_times(fname, mtime, atime) != 0 &&
244 !S_ISDIR(st->st_mode)) {
245 rprintf(FERROR, "failed to set times on %s: %s\n",
246 full_fname(fname), strerror(errno));
252 change_uid = am_root && preserve_uid && st->st_uid != file->uid;
253 --- rsync.h 17 Apr 2004 17:14:16 -0000 1.197
254 +++ rsync.h 20 Apr 2004 23:44:18 -0000
256 #define XMIT_HAS_IDEV_DATA (1<<9)
257 #define XMIT_SAME_DEV (1<<10)
258 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
259 +#define XMIT_SAME_ATIME (1<<12)
261 /* These flags are used in the live flist data. */
263 @@ -419,6 +420,7 @@ struct file_struct {
271 --- rsync.yo 17 Apr 2004 18:40:16 -0000 1.159
272 +++ rsync.yo 20 Apr 2004 23:44:18 -0000
273 @@ -299,6 +299,7 @@ verb(
274 -g, --group preserve group
275 -D, --devices preserve devices (root only)
276 -t, --times preserve times
277 + -A, --copy-atimes copy access times
278 -S, --sparse handle sparse files efficiently
279 -n, --dry-run show what would have been transferred
280 -W, --whole-file copy whole files, no incremental checks
281 @@ -536,6 +537,11 @@ modified cannot be effective; in other w
282 cause the next transfer to behave as if it used -I, and all files will have
283 their checksums compared and show up in log messages even if they haven't
286 +dit(bf(-A, --copy-atimes)) This tells rsync to transfer access times
287 +along with the files and update them on the remote system. Note that
288 +reading the source file may update the atime and hence repeated rsync
289 +copies with --copy-atimes may copy files unnecessarily.
291 dit(bf(-n, --dry-run)) This tells rsync to not do any file transfers,
292 instead it will just report the actions it would have taken.
293 --- tls.c 9 Apr 2004 20:22:44 -0000 1.19
294 +++ tls.c 20 Apr 2004 23:44:18 -0000
301 #define PROGRAM "tls"
303 @@ -48,6 +49,7 @@ int read_only = 1;
305 int preserve_perms = 0;
307 +static int display_atime = 0;
309 static void failed (char const *what,
311 @@ -57,14 +59,29 @@ static void failed (char const *what,
315 +static void storetime(char *dest, time_t t)
318 + struct tm *mt = gmtime(&t);
320 + sprintf(dest, "%04d-%02d-%02d %02d:%02d:%02d ",
321 + mt->tm_year + 1900,
332 static void list_file (const char *fname)
335 char permbuf[PERMSTRING_SIZE];
342 if (do_lstat(fname, &buf) == -1)
343 @@ -97,19 +114,8 @@ static void list_file (const char *fname
345 permstring(permbuf, buf.st_mode);
347 - if (buf.st_mtime) {
348 - mt = gmtime(&buf.st_mtime);
350 - sprintf(datebuf, "%04d-%02d-%02d %02d:%02d:%02d",
351 - mt->tm_year + 1900,
358 - strcpy(datebuf, " ");
360 + storetime(mtimebuf, buf.st_mtime);
361 + storetime(atimebuf, buf.st_atime);
363 /* TODO: Perhaps escape special characters in fname? */
365 @@ -120,24 +126,55 @@ static void list_file (const char *fname
366 (long)minor(buf.st_rdev));
367 } else /* NB: use double for size since it might not fit in a long. */
368 printf("%12.0f", (double)buf.st_size);
369 - printf(" %6ld.%-6ld %6ld %s %s%s\n",
370 + printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
371 (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
372 - datebuf, fname, linkbuf);
373 + mtimebuf, display_atime ? atimebuf : "",
377 +static struct poptOption long_options[] = {
378 + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
379 + {"atime", 'u', POPT_ARG_NONE, &display_atime, 0, 0, 0},
380 + {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
384 +static void tls_usage(int ret)
386 + fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
387 + "Trivial file listing program for portably checking rsync\n");
392 main(int argc, char *argv[])
395 - fprintf (stderr, "usage: " PROGRAM " DIR ...\n"
396 - "Trivial file listing program for portably checking rsync\n");
399 + const char **extra_args;
402 + pc = poptGetContext(PROGRAM, argc, (const char **)argv,
404 + while ((opt = poptGetNextOpt(pc)) != -1) {
411 + poptBadOption(pc, POPT_BADOPTION_NOALIAS),
412 + poptStrerror(opt));
417 - for (argv++; *argv; argv++) {
420 + extra_args = poptGetArgs(pc);
421 + if (*extra_args == NULL)
424 + for (; *extra_args; extra_args++)
425 + list_file(*extra_args);
426 + poptFreeContext(pc);
430 --- util.c 17 Apr 2004 17:06:03 -0000 1.136
431 +++ util.c 20 Apr 2004 23:44:19 -0000
432 @@ -124,32 +124,40 @@ void overflow(char *str)
436 -int set_modtime(char *fname, time_t modtime)
437 +int set_times(char *fname, time_t modtime, time_t atime)
444 - rprintf(FINFO, "set modtime of %s to (%ld) %s",
445 + char mtimebuf[200];
446 + char atimebuf[200];
448 + strlcpy(mtimebuf, timestring(modtime), sizeof(mtimebuf));
449 + strlcpy(atimebuf, timestring(atime), sizeof(atimebuf));
452 + "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
453 fname, (long) modtime,
454 - asctime(localtime(&modtime)));
456 + (long) atime, atimebuf);
462 - tbuf.actime = time(NULL);
463 + tbuf.actime = atime;
464 tbuf.modtime = modtime;
465 return utime(fname,&tbuf);
466 #elif defined(HAVE_UTIME)
471 return utime(fname,t);
474 - t[0].tv_sec = time(NULL);
475 + t[0].tv_sec = atime;
477 t[1].tv_sec = modtime;
479 @@ -1052,8 +1060,8 @@ int msleep(int t)
483 - * Determine if two file modification times are equivalent (either
484 - * exact or in the modification timestamp window established by
485 + * Determine if two file times are equivalent (either
486 + * exact or in the timestamp window established by
489 * @retval 0 if the times should be treated as the same
490 @@ -1062,7 +1070,7 @@ int msleep(int t)
492 * @retval -1 if the 2nd is later
494 -int cmp_modtime(time_t file1, time_t file2)
495 +int cmp_time(time_t file1, time_t file2)
497 extern int modify_window;
499 --- /dev/null 1 Jan 1970 00:00:00 -0000
500 +++ testsuite/copy-atimes.test 20 Apr 2004 23:44:19 -0000
504 +# Test rsync copying atimes
506 +. $srcdir/testsuite/rsync.fns
510 +fromdir="$scratchdir/from"
511 +todir="$scratchdir/to"
515 +touch "$fromdir/foo"
516 +touch -a -t 200102031717.42 "$fromdir/foo"
520 +checkit "$RSYNC -rtAgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
522 +# The script would have aborted on error, so getting here means we've won.
524 --- testsuite/rsync.fns 4 Feb 2004 07:32:48 -0000 1.59
525 +++ testsuite/rsync.fns 20 Apr 2004 23:44:19 -0000
526 @@ -51,7 +51,7 @@ printmsg() {
530 - find "$@" -print | sort | xargs "$TOOLDIR/tls"
531 + find "$@" -print | sort | xargs "$TOOLDIR/tls" $TLS_ARGS
535 @@ -151,6 +151,8 @@ checkit() {
536 # We can just write everything to stdout/stderr, because the
537 # wrapper hides it unless there is a problem.
539 + ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from
541 echo "Running: \"$1\""
544 @@ -159,6 +161,12 @@ checkit() {
548 + echo "check how the directory listings compare with diff:"
550 + ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to
551 + diff $diffopt ${TMP}/ls-from ${TMP}/ls-to || failed=YES
553 + echo "-------------"
554 echo "check how the files compare with diff:"
556 for f in `cd "$2"; find . -type f -print `
557 @@ -166,12 +174,6 @@ checkit() {
558 diff $diffopt "$2"/"$f" "$3"/"$f" || failed=YES
561 - echo "-------------"
562 - echo "check how the directory listings compare with diff:"
564 - ( cd "$2" && rsync_ls_lR . ) > ${TMP}/ls-from
565 - ( cd "$3" && rsync_ls_lR . ) > ${TMP}/ls-to
566 - diff $diffopt ${TMP}/ls-from ${TMP}/ls-to || failed=YES
567 if [ -z "${failed}" ] ; then