1 After applying this patch and running configure, you MUST run this
7 --- orig/batch.c 2005-04-09 18:00:28
8 +++ batch.c 2004-07-03 20:15:41
9 @@ -208,6 +208,8 @@ void show_flist(int index, struct file_s
10 rprintf(FINFO, "flist->flags=%#x\n", fptr[i]->flags);
11 rprintf(FINFO, "flist->modtime=%#lx\n",
12 (long unsigned) fptr[i]->modtime);
13 + rprintf(FINFO, "flist->atime=%#lx\n",
14 + (long unsigned) fptr[i]->atime);
15 rprintf(FINFO, "flist->length=%.0f\n",
16 (double) fptr[i]->length);
17 rprintf(FINFO, "flist->mode=%#o\n", (int) fptr[i]->mode);
18 --- orig/flist.c 2005-05-28 08:24:57
19 +++ flist.c 2005-02-07 21:06:04
20 @@ -54,6 +54,7 @@ extern int relative_paths;
21 extern int implied_dirs;
22 extern int copy_links;
23 extern int copy_unsafe_links;
24 +extern int copy_atimes;
25 extern int protocol_version;
26 extern int sanitize_paths;
27 extern int orig_umask;
28 @@ -141,16 +142,18 @@ static void list_file_entry(struct file_
31 if (preserve_links && S_ISLNK(f->mode)) {
32 - rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
33 + rprintf(FINFO, "%s %11.0f %s %s %s -> %s\n",
35 (double)f->length, timestring(f->modtime),
36 + timestring(f->atime),
37 safe_fname(f_name(f)), safe_fname(f->u.link));
41 - rprintf(FINFO, "%s %11.0f %s %s\n",
42 + rprintf(FINFO, "%s %11.0f %s %s %s\n",
44 (double)f->length, timestring(f->modtime),
45 + timestring(f->atime),
46 safe_fname(f_name(f)));
49 @@ -314,6 +317,7 @@ void send_file_entry(struct file_struct
52 static time_t modtime;
53 + static time_t atime;
57 @@ -329,7 +333,7 @@ void send_file_entry(struct file_struct
61 - modtime = 0, mode = 0;
62 + modtime = 0, atime = 0, mode = 0;
63 dev = 0, rdev = makedev(0, 0);
66 @@ -378,6 +382,12 @@ void send_file_entry(struct file_struct
67 flags |= XMIT_SAME_TIME;
69 modtime = file->modtime;
70 + if (copy_atimes && !S_ISDIR(mode)) {
71 + if (file->atime == atime)
72 + flags |= XMIT_SAME_ATIME;
74 + atime = file->atime;
77 #ifdef SUPPORT_HARD_LINKS
78 if (file->link_u.idev) {
79 @@ -433,6 +443,8 @@ void send_file_entry(struct file_struct
80 write_int(f, modtime);
81 if (!(flags & XMIT_SAME_MODE))
82 write_int(f, to_wire_mode(mode));
83 + if (copy_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
84 + write_int(f, atime);
85 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
88 @@ -506,6 +518,7 @@ static struct file_struct *receive_file_
89 unsigned short flags, int f)
91 static time_t modtime;
92 + static time_t atime;
96 @@ -524,7 +537,7 @@ static struct file_struct *receive_file_
97 struct file_struct *file;
100 - modtime = 0, mode = 0;
101 + modtime = 0, atime = 0, mode = 0;
102 dev = 0, rdev = makedev(0, 0);
105 @@ -580,6 +593,8 @@ static struct file_struct *receive_file_
106 modtime = (time_t)read_int(f);
107 if (!(flags & XMIT_SAME_MODE))
108 mode = from_wire_mode(read_int(f));
109 + if (copy_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
110 + atime = (time_t)read_int(f);
112 if (preserve_uid && !(flags & XMIT_SAME_UID))
113 uid = (uid_t)read_int(f);
114 @@ -630,6 +645,7 @@ static struct file_struct *receive_file_
117 file->modtime = modtime;
118 + file->atime = atime;
119 file->length = file_length;
122 @@ -882,6 +898,7 @@ skip_filters:
125 file->modtime = st.st_mtime;
126 + file->atime = st.st_atime;
127 file->length = st.st_size;
128 file->mode = st.st_mode;
129 file->uid = st.st_uid;
130 --- orig/generator.c 2005-05-22 20:53:34
131 +++ generator.c 2004-11-03 23:02:12
132 @@ -375,7 +375,7 @@ static int unchanged_file(char *fn, stru
136 - return cmp_modtime(st->st_mtime, file->modtime) == 0;
137 + return cmp_time(st->st_mtime, file->modtime) == 0;
141 @@ -849,7 +849,7 @@ static void recv_generator(char *fname,
144 if (update_only && statret == 0
145 - && cmp_modtime(st.st_mtime, file->modtime) > 0) {
146 + && cmp_time(st.st_mtime, file->modtime) > 0) {
148 rprintf(FINFO, "%s is newer\n", safe_fname(fname));
150 --- orig/options.c 2005-05-19 08:52:42
151 +++ options.c 2005-02-21 10:53:28
152 @@ -49,6 +49,7 @@ int preserve_uid = 0;
153 int preserve_gid = 0;
154 int preserve_times = 0;
155 int omit_dir_times = 0;
156 +int copy_atimes = 0;
160 @@ -286,6 +287,7 @@ void usage(enum logcode F)
161 rprintf(F," -g, --group preserve group\n");
162 rprintf(F," -D, --devices preserve devices (root only)\n");
163 rprintf(F," -t, --times preserve times\n");
164 + rprintf(F," -A, --copy-atimes copy access times\n");
165 rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
166 rprintf(F," -S, --sparse handle sparse files efficiently\n");
167 rprintf(F," -n, --dry-run show what would have been transferred\n");
168 @@ -413,6 +415,7 @@ static struct poptOption long_options[]
169 {"devices", 'D', POPT_ARG_NONE, &preserve_devices, 0, 0, 0 },
170 {"times", 't', POPT_ARG_NONE, &preserve_times, 0, 0, 0 },
171 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
172 + {"copy-atimes", 'A', POPT_ARG_NONE, ©_atimes, 0, 0, 0 },
173 {"checksum", 'c', POPT_ARG_NONE, &always_checksum, 0, 0, 0 },
174 {"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
175 {"quiet", 'q', POPT_ARG_NONE, 0, 'q', 0, 0 },
176 @@ -1290,6 +1293,8 @@ void server_options(char **args,int *arg
182 if (omit_dir_times == 2 && am_sender)
185 --- orig/rsync.c 2005-03-16 02:19:30
186 +++ rsync.c 2005-02-21 10:57:03
187 @@ -27,6 +27,7 @@ extern int dry_run;
188 extern int daemon_log_format_has_i;
189 extern int preserve_times;
190 extern int omit_dir_times;
191 +extern int copy_atimes;
193 extern int am_server;
194 extern int am_sender;
195 @@ -56,6 +57,7 @@ int set_perms(char *fname,struct file_st
198 int change_uid, change_gid;
199 + time_t atime, mtime;
203 @@ -68,17 +70,27 @@ int set_perms(char *fname,struct file_st
207 + if (!copy_atimes || S_ISLNK(st->st_mode) || S_ISDIR(st->st_mode))
208 + flags |= PERMS_SKIP_ATIME;
209 if (!preserve_times || S_ISLNK(st->st_mode)
210 || (S_ISDIR(st->st_mode) && omit_dir_times))
211 flags |= PERMS_SKIP_MTIME;
212 + if (!(flags & PERMS_SKIP_ATIME)
213 + && cmp_time(st->st_atime, file->atime) != 0) {
214 + atime = file->atime;
217 + atime = st->st_atime;
218 if (!(flags & PERMS_SKIP_MTIME)
219 - && cmp_modtime(st->st_mtime, file->modtime) != 0) {
220 - if (set_modtime(fname,file->modtime) != 0) {
221 - rsyserr(FERROR, errno, "failed to set times on %s",
222 - full_fname(fname));
225 + && cmp_time(st->st_mtime, file->modtime) != 0) {
226 + mtime = file->modtime;
229 + mtime = st->st_mtime;
230 + if (updated && set_times(fname, mtime, atime) != 0) {
231 + rsyserr(FERROR, errno, "failed to set times on %s",
232 + full_fname(fname));
236 change_uid = am_root && preserve_uid && st->st_uid != file->uid;
237 --- orig/rsync.h 2005-05-03 17:11:01
238 +++ rsync.h 2004-07-03 20:15:41
240 #define XMIT_HAS_IDEV_DATA (1<<9)
241 #define XMIT_SAME_DEV (1<<10)
242 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
243 +#define XMIT_SAME_ATIME (1<<12)
245 /* These flags are used in the live flist data. */
249 #define PERMS_REPORT (1<<0)
250 #define PERMS_SKIP_MTIME (1<<1)
251 +#define PERMS_SKIP_ATIME (1<<2)
254 #define NORMAL_FLUSH 0
255 @@ -509,6 +511,7 @@ struct file_struct {
263 --- orig/rsync.yo 2005-05-22 20:53:34
264 +++ rsync.yo 2005-01-24 01:57:18
265 @@ -322,6 +322,7 @@ to the detailed description below for a
266 -D, --devices preserve devices (root only)
267 -t, --times preserve times
268 -O, --omit-dir-times omit directories when preserving times
269 + -A, --copy-atimes copy access times
270 -S, --sparse handle sparse files efficiently
271 -n, --dry-run show what would have been transferred
272 -W, --whole-file copy files whole (without rsync algorithm)
273 @@ -659,6 +660,11 @@ it is preserving modification times (see
274 the directories on the receiving side, it is a good idea to use bf(-O).
275 This option is inferred if you use bf(--backup) without bf(--backup-dir).
277 +dit(bf(-A, --copy-atimes)) This tells rsync to transfer access times
278 +along with the files and update them on the remote system. Note that
279 +reading the source file may update the atime and hence repeated rsync
280 +copies with --copy-atimes may copy files unnecessarily.
282 dit(bf(-n, --dry-run)) This tells rsync to not do any file transfers,
283 instead it will just report the actions it would have taken.
285 --- orig/testsuite/copy-atimes.test 2004-06-30 00:06:23
286 +++ testsuite/copy-atimes.test 2004-06-30 00:06:23
290 +# Test rsync copying atimes
292 +. "$suitedir/rsync.fns"
298 +touch "$fromdir/foo"
299 +touch -a -t 200102031717.42 "$fromdir/foo"
303 +checkit "$RSYNC -rtAgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
305 +# The script would have aborted on error, so getting here means we've won.
307 --- orig/testsuite/rsync.fns 2005-02-21 07:26:59
308 +++ testsuite/rsync.fns 2005-02-21 07:30:11
309 @@ -50,7 +50,7 @@ printmsg() {
313 - find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
314 + find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
318 @@ -158,6 +158,8 @@ checkit() {
319 # We can just write everything to stdout/stderr, because the
320 # wrapper hides it unless there is a problem.
322 + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
324 echo "Running: \"$1\""
327 @@ -168,7 +170,6 @@ checkit() {
329 echo "check how the directory listings compare with diff:"
331 - ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
332 ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
333 diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
335 --- orig/tls.c 2005-01-19 19:30:29
336 +++ tls.c 2005-03-23 17:49:48
343 #define PROGRAM "tls"
345 @@ -48,6 +49,7 @@ int read_only = 1;
347 int preserve_perms = 0;
349 +static int display_atime = 0;
351 static void failed(char const *what, char const *where)
353 @@ -56,14 +58,29 @@ static void failed(char const *what, cha
357 +static void storetime(char *dest, time_t t)
360 + struct tm *mt = gmtime(&t);
362 + sprintf(dest, "%04d-%02d-%02d %02d:%02d:%02d ",
363 + mt->tm_year + 1900,
374 static void list_file(const char *fname)
377 char permbuf[PERMSTRING_SIZE];
384 if (do_lstat(fname, &buf) < 0)
385 @@ -96,19 +113,8 @@ static void list_file(const char *fname)
387 permstring(permbuf, buf.st_mode);
389 - if (buf.st_mtime) {
390 - mt = gmtime(&buf.st_mtime);
392 - sprintf(datebuf, "%04d-%02d-%02d %02d:%02d:%02d",
393 - mt->tm_year + 1900,
400 - strcpy(datebuf, " ");
402 + storetime(mtimebuf, buf.st_mtime);
403 + storetime(atimebuf, buf.st_atime);
405 /* TODO: Perhaps escape special characters in fname? */
407 @@ -119,24 +125,55 @@ static void list_file(const char *fname)
408 (long)minor(buf.st_rdev));
409 } else /* NB: use double for size since it might not fit in a long. */
410 printf("%12.0f", (double)buf.st_size);
411 - printf(" %6ld.%-6ld %6ld %s %s%s\n",
412 + printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
413 (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
414 - datebuf, fname, linkbuf);
415 + mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "",
419 +static struct poptOption long_options[] = {
420 + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
421 + {"atime", 'u', POPT_ARG_NONE, &display_atime, 0, 0, 0},
422 + {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
426 +static void tls_usage(int ret)
428 + fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
429 + "Trivial file listing program for portably checking rsync\n");
434 main(int argc, char *argv[])
437 - fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
438 - "Trivial file listing program for portably checking rsync\n");
441 + const char **extra_args;
444 + pc = poptGetContext(PROGRAM, argc, (const char **)argv,
446 + while ((opt = poptGetNextOpt(pc)) != -1) {
453 + poptBadOption(pc, POPT_BADOPTION_NOALIAS),
454 + poptStrerror(opt));
459 - for (argv++; *argv; argv++) {
462 + extra_args = poptGetArgs(pc);
463 + if (*extra_args == NULL)
466 + for (; *extra_args; extra_args++)
467 + list_file(*extra_args);
468 + poptFreeContext(pc);
472 --- orig/util.c 2005-05-03 16:47:33
473 +++ util.c 2005-02-07 21:09:12
474 @@ -128,12 +128,17 @@ void overflow(char *str)
478 -int set_modtime(char *fname, time_t modtime)
479 +int set_times(char *fname, time_t modtime, time_t atime)
482 - rprintf(FINFO, "set modtime of %s to (%ld) %s",
483 + char mtimebuf[200];
485 + strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
487 + "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
488 safe_fname(fname), (long)modtime,
489 - asctime(localtime(&modtime)));
491 + (long)atime, timestring(atime));
495 @@ -142,17 +147,17 @@ int set_modtime(char *fname, time_t modt
499 - tbuf.actime = time(NULL);
500 + tbuf.actime = atime;
501 tbuf.modtime = modtime;
502 return utime(fname,&tbuf);
503 #elif defined HAVE_UTIME
508 return utime(fname,t);
511 - t[0].tv_sec = time(NULL);
512 + t[0].tv_sec = atime;
514 t[1].tv_sec = modtime;
516 @@ -1156,8 +1161,8 @@ int msleep(int t)
520 - * Determine if two file modification times are equivalent (either
521 - * exact or in the modification timestamp window established by
522 + * Determine if two file times are equivalent (either
523 + * exact or in the timestamp window established by
526 * @retval 0 if the times should be treated as the same
527 @@ -1166,7 +1171,7 @@ int msleep(int t)
529 * @retval -1 if the 2nd is later
531 -int cmp_modtime(time_t file1, time_t file2)
532 +int cmp_time(time_t file1, time_t file2)
535 if (file2 - file1 <= modify_window)