1 To use this patch, run these commands for a successful build:
3 patch -p1 <patches/atimes.diff
5 ./configure (optional if already run)
11 @@ -46,6 +46,7 @@ extern int preserve_devices;
12 extern int preserve_specials;
13 extern int preserve_uid;
14 extern int preserve_gid;
15 +extern int preserve_atimes;
16 extern int relative_paths;
17 extern int implied_dirs;
18 extern int prune_empty_dirs;
19 @@ -79,7 +80,13 @@ void init_flist(void)
22 /* Figure out how big the file_struct is without trailing padding */
23 - file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags;
24 + if (preserve_atimes)
25 + file_struct_len = offsetof(struct file_struct, fl4g5);
27 + file_struct_len = offsetof(struct file_struct, atime);
28 + /* The "flags" uchar is no longer accessed directly, so I
29 + * mangled the name to fl4g5 as a reminder. */
30 + file_struct_len += sizeof f.fl4g5;
31 checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
34 @@ -135,16 +142,18 @@ static void list_file_entry(struct file_
37 if (preserve_links && S_ISLNK(f->mode)) {
38 - rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
39 + rprintf(FINFO, "%s %11.0f %s %s %s -> %s\n",
41 (double)f->length, timestring(f->modtime),
42 + preserve_atimes ? timestring(f->atime) : "",
43 f_name(f, NULL), f->u.link);
47 - rprintf(FINFO, "%s %11.0f %s %s\n",
48 + rprintf(FINFO, "%s %11.0f %s %s %s\n",
50 (double)f->length, timestring(f->modtime),
51 + preserve_atimes ? timestring(f->atime) : "",
55 @@ -302,6 +311,7 @@ static void send_file_entry(struct file_
58 static time_t modtime;
59 + static time_t atime;
63 @@ -317,7 +327,7 @@ static void send_file_entry(struct file_
67 - modtime = 0, mode = 0;
68 + modtime = 0, atime = 0, mode = 0;
69 dev = 0, rdev = MAKEDEV(0, 0);
72 @@ -327,7 +337,7 @@ static void send_file_entry(struct file_
76 - flags = file->flags & XMIT_TOP_DIR;
77 + flags = FFLAGS(file) & XMIT_TOP_DIR;
79 if (file->mode == mode)
80 flags |= XMIT_SAME_MODE;
81 @@ -363,6 +373,12 @@ static void send_file_entry(struct file_
82 flags |= XMIT_SAME_TIME;
84 modtime = file->modtime;
85 + if (preserve_atimes && !S_ISDIR(mode)) {
86 + if (file->atime == atime)
87 + flags |= XMIT_SAME_ATIME;
89 + atime = file->atime;
92 #ifdef SUPPORT_HARD_LINKS
93 if (file->link_u.idev) {
94 @@ -416,6 +432,8 @@ static void send_file_entry(struct file_
95 write_int(f, modtime);
96 if (!(flags & XMIT_SAME_MODE))
97 write_int(f, to_wire_mode(mode));
98 + if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
99 + write_int(f, atime);
100 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
103 @@ -482,6 +500,7 @@ static struct file_struct *receive_file_
104 unsigned short flags, int f)
106 static time_t modtime;
107 + static time_t atime;
111 @@ -500,7 +519,7 @@ static struct file_struct *receive_file_
112 struct file_struct *file;
115 - modtime = 0, mode = 0;
116 + modtime = 0, atime = 0, mode = 0;
117 dev = 0, rdev = MAKEDEV(0, 0);
120 @@ -556,6 +575,8 @@ static struct file_struct *receive_file_
121 modtime = (time_t)read_int(f);
122 if (!(flags & XMIT_SAME_MODE))
123 mode = from_wire_mode(read_int(f));
124 + if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
125 + atime = (time_t)read_int(f);
127 if (chmod_modes && !S_ISLNK(mode))
128 mode = tweak_mode(mode, chmod_modes);
129 @@ -611,6 +632,8 @@ static struct file_struct *receive_file_
133 + if (preserve_atimes)
134 + file->atime = atime;
137 file->dirname = lastdir = bp;
138 @@ -636,12 +659,12 @@ static struct file_struct *receive_file_
139 && lastname[del_hier_name_len-1] == '.'
140 && lastname[del_hier_name_len-2] == '/')
141 del_hier_name_len -= 2;
142 - file->flags |= FLAG_TOP_DIR | FLAG_DEL_HERE;
143 + FFLAGS(file) |= FLAG_TOP_DIR | FLAG_DEL_HERE;
144 } else if (in_del_hier) {
145 if (!relative_paths || !del_hier_name_len
146 || (l1 >= del_hier_name_len
147 && lastname[del_hier_name_len] == '/'))
148 - file->flags |= FLAG_DEL_HERE;
149 + FFLAGS(file) |= FLAG_DEL_HERE;
153 @@ -858,12 +881,14 @@ struct file_struct *make_file(char *fnam
154 memset(bp, 0, file_struct_len);
155 bp += file_struct_len;
157 - file->flags = flags;
158 + FFLAGS(file) = flags;
159 file->modtime = st.st_mtime;
160 file->length = st.st_size;
161 file->mode = st.st_mode;
162 file->uid = st.st_uid;
163 file->gid = st.st_gid;
164 + if (preserve_atimes)
165 + file->atime = st.st_atime;
167 #ifdef SUPPORT_HARD_LINKS
168 if (flist && flist->hlink_pool) {
169 @@ -976,7 +1001,7 @@ static void send_if_directory(int f, str
170 char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
172 if (S_ISDIR(file->mode)
173 - && !(file->flags & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
174 + && !(FFLAGS(file) & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
176 unsigned int len = strlen(fbuf);
177 if (len > 1 && fbuf[len-1] == '/')
178 @@ -1586,8 +1611,9 @@ static void clean_flist(struct file_list
180 /* Make sure we don't lose track of a user-specified
182 - flist->files[keep]->flags |= flist->files[drop]->flags
183 - & (FLAG_TOP_DIR|FLAG_DEL_HERE);
184 + FFLAGS(flist->files[keep])
185 + |= FFLAGS(flist->files[drop])
186 + & (FLAG_TOP_DIR|FLAG_DEL_HERE);
188 clear_file(flist->files[drop], flist);
190 @@ -1711,7 +1737,7 @@ static void output_flist(struct file_lis
191 file->dirname ? file->dirname : "",
192 file->dirname ? "/" : "", NS(file->basename),
193 S_ISDIR(file->mode) ? "/" : "", (int)file->mode,
194 - (double)file->length, uidbuf, gidbuf, file->flags);
195 + (double)file->length, uidbuf, gidbuf, FFLAGS(file));
201 @@ -43,6 +43,7 @@ extern int preserve_perms;
202 extern int preserve_uid;
203 extern int preserve_gid;
204 extern int preserve_times;
205 +extern int preserve_atimes;
206 extern int omit_dir_times;
207 extern int delete_mode;
208 extern int delete_before;
209 @@ -90,6 +91,7 @@ extern dev_t filesystem_dev;
210 extern char *backup_dir;
211 extern char *backup_suffix;
212 extern int backup_suffix_len;
213 +extern unsigned int file_struct_len;
214 extern struct file_list *the_file_list;
215 extern struct filter_list_struct server_filter_list;
217 @@ -185,7 +187,7 @@ static int delete_item(char *fname, int
218 for (j = dirlist->count; j--; ) {
219 struct file_struct *fp = dirlist->files[j];
221 - if (fp->flags & FLAG_MOUNT_POINT)
222 + if (FFLAGS(fp) & FLAG_MOUNT_POINT)
225 strlcpy(p, fp->basename, remainder);
226 @@ -263,7 +265,7 @@ static void delete_in_dir(struct file_li
227 filt_array[cur_depth] = push_local_filters(fbuf, dlen);
229 if (one_file_system) {
230 - if (file->flags & FLAG_TOP_DIR)
231 + if (FFLAGS(file) & FLAG_TOP_DIR)
232 filesystem_dev = stp->st_dev;
233 else if (filesystem_dev != stp->st_dev)
235 @@ -275,7 +277,7 @@ static void delete_in_dir(struct file_li
236 * from the filesystem. */
237 for (i = dirlist->count; i--; ) {
238 struct file_struct *fp = dirlist->files[i];
239 - if (!fp->basename || fp->flags & FLAG_MOUNT_POINT)
240 + if (!fp->basename || FFLAGS(fp) & FLAG_MOUNT_POINT)
242 if (flist_find(flist, fp) < 0) {
244 @@ -301,11 +303,11 @@ static void do_delete_pass(struct file_l
245 for (j = 0; j < flist->count; j++) {
246 struct file_struct *file = flist->files[j];
248 - if (!(file->flags & FLAG_DEL_HERE))
249 + if (!(FFLAGS(file) & FLAG_DEL_HERE))
253 - if (verbose > 1 && file->flags & FLAG_TOP_DIR)
254 + if (verbose > 1 && FFLAGS(file) & FLAG_TOP_DIR)
255 rprintf(FINFO, "deleting in %s\n", fbuf);
257 if (link_stat(fbuf, &st, keep_dirlinks) < 0
258 @@ -350,6 +352,9 @@ void itemize(struct file_struct *file, i
259 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
260 || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
261 iflags |= ITEM_REPORT_TIME;
262 + if (preserve_atimes && !S_ISDIR(file->mode) && !S_ISLNK(file->mode)
263 + && cmp_time(file->atime, st->st_atime) != 0)
264 + iflags |= ITEM_REPORT_ATIME;
265 if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
266 iflags |= ITEM_REPORT_PERMS;
267 if (preserve_uid && am_root && file->uid != st->st_uid)
268 @@ -553,7 +558,7 @@ static int find_fuzzy(struct file_struct
271 if (!S_ISREG(fp->mode) || !fp->length
272 - || fp->flags & FLAG_NO_FUZZY)
273 + || FFLAGS(fp) & FLAG_NO_FUZZY)
277 @@ -661,6 +666,8 @@ static int try_dests_reg(struct file_str
278 if (hard_link_one(file, ndx, fname, 0, stp,
279 cmpbuf, 1, i, code) < 0)
281 + if (preserve_atimes)
282 + set_file_attrs(fname, file, stp, 0);
283 if (preserve_hard_links && file->link_u.links) {
285 file->link_u.links->link_dest_used = j + 1;
286 @@ -1012,7 +1019,7 @@ static void recv_generator(char *fname,
287 rsyserr(FERROR, errno,
288 "recv_generator: mkdir %s failed",
290 - file->flags |= FLAG_MISSING;
291 + FFLAGS(file) |= FLAG_MISSING;
292 if (ndx+1 < the_file_list->count
293 && the_file_list->files[ndx+1]->dir.depth > file->dir.depth) {
295 @@ -1028,7 +1035,7 @@ static void recv_generator(char *fname,
296 if (real_ret != 0 && one_file_system)
297 real_st.st_dev = filesystem_dev;
298 if (delete_during && f_out != -1 && !phase && dry_run < 2
299 - && (file->flags & FLAG_DEL_HERE))
300 + && (FFLAGS(file) & FLAG_DEL_HERE))
301 delete_in_dir(the_file_list, fname, file, &real_st);
304 @@ -1324,7 +1331,7 @@ static void recv_generator(char *fname,
306 int j = flist_find(fuzzy_dirlist, file);
307 if (j >= 0) /* don't use changing file as future fuzzy basis */
308 - fuzzy_dirlist->files[j]->flags |= FLAG_NO_FUZZY;
309 + FFLAGS(fuzzy_dirlist->files[j]) |= FLAG_NO_FUZZY;
313 @@ -1589,7 +1596,7 @@ void generate_files(int f_out, struct fi
315 if (!need_retouch_dir_times && file->mode & S_IWUSR)
317 - if (file->flags & FLAG_MISSING) {
318 + if (FFLAGS(file) & FLAG_MISSING) {
319 int missing = file->dir.depth;
320 while (++i < flist->count) {
321 file = flist->files[i];
324 @@ -30,6 +30,7 @@ extern int make_backups;
325 extern int remove_source_files;
326 extern int stdout_format_has_i;
327 extern char *basis_dir[];
328 +extern unsigned int file_struct_len;
329 extern struct file_list *the_file_list;
331 #ifdef SUPPORT_HARD_LINKS
332 @@ -91,10 +92,10 @@ static void link_idev_data(void)
333 FPTR(cur)->link_u.links = pool_talloc(hlink_pool,
334 struct hlink, 1, "hlink_list");
336 - FPTR(head)->flags |= FLAG_HLINK_TOL;
337 + FFLAGS(FPTR(head)) |= FLAG_HLINK_TOL;
338 FPTR(cur)->F_HLINDEX = to;
339 FPTR(cur)->F_NEXT = head;
340 - FPTR(cur)->flags |= FLAG_HLINK_EOL;
341 + FFLAGS(FPTR(cur)) |= FLAG_HLINK_EOL;
342 FPTR(cur)->link_u.links->link_dest_used = 0;
343 hlink_list[to++] = head;
345 @@ -181,7 +182,7 @@ int hard_link_check(struct file_struct *
347 #ifdef SUPPORT_HARD_LINKS
349 - if (skip && !(file->flags & FLAG_HLINK_EOL))
350 + if (skip && !(FFLAGS(file) & FLAG_HLINK_EOL))
351 head = hlink_list[file->F_HLINDEX] = file->F_NEXT;
353 head = hlink_list[file->F_HLINDEX];
354 @@ -289,8 +290,8 @@ void hard_link_cluster(struct file_struc
355 file->F_HLINDEX = FINISHED_LINK;
356 if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
358 - if (!(file->flags & FLAG_HLINK_TOL)) {
359 - while (!(file->flags & FLAG_HLINK_EOL)) {
360 + if (!(FFLAGS(file) & FLAG_HLINK_TOL)) {
361 + while (!(FFLAGS(file) & FLAG_HLINK_EOL)) {
365 @@ -310,6 +311,6 @@ void hard_link_cluster(struct file_struc
366 send_msg(MSG_SUCCESS, numbuf, 4);
368 file->F_HLINDEX = FINISHED_LINK;
369 - } while (!(file->flags & FLAG_HLINK_EOL));
370 + } while (!(FFLAGS(file) & FLAG_HLINK_EOL));
375 @@ -37,6 +37,7 @@ extern int msg_fd_out;
376 extern int allow_8bit_chars;
377 extern int protocol_version;
378 extern int preserve_times;
379 +extern int preserve_atimes;
380 extern int stdout_format_has_i;
381 extern int stdout_format_has_o_or_i;
382 extern int logfile_format_has_i;
383 @@ -606,7 +607,8 @@ static void log_formatted(enum logcode c
384 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
385 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
386 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
388 + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.'
389 + : S_ISLNK(file->mode) ? 'U' : 'u';
392 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
395 @@ -55,6 +55,7 @@ int preserve_uid = 0;
396 int preserve_gid = 0;
397 int preserve_times = 0;
398 int omit_dir_times = 0;
399 +int preserve_atimes = 0;
403 @@ -311,8 +312,9 @@ void usage(enum logcode F)
404 rprintf(F," --devices preserve device files (super-user only)\n");
405 rprintf(F," --specials preserve special files\n");
406 rprintf(F," -D same as --devices --specials\n");
407 - rprintf(F," -t, --times preserve times\n");
408 - rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
409 + rprintf(F," -t, --times preserve modify times\n");
410 + rprintf(F," -O, --omit-dir-times omit directories when preserving modify times\n");
411 + rprintf(F," -U, --atimes preserve access (use) times\n");
412 rprintf(F," --super receiver attempts super-user activities\n");
413 rprintf(F," -S, --sparse handle sparse files efficiently\n");
414 rprintf(F," -n, --dry-run show what would have been transferred\n");
415 @@ -428,6 +430,9 @@ static struct poptOption long_options[]
416 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
417 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
418 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
419 + {"atimes", 'U', POPT_ARG_VAL, &preserve_atimes, 1, 0, 0 },
420 + {"no-atimes", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
421 + {"no-k", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
422 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
423 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
424 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
425 @@ -1538,6 +1543,8 @@ void server_options(char **args,int *arg
429 + if (preserve_atimes)
433 else if (preserve_executability && am_sender)
436 @@ -34,6 +34,7 @@ extern int verbose;
438 extern int preserve_perms;
439 extern int preserve_executability;
440 +extern int preserve_atimes;
441 extern int preserve_times;
442 extern int omit_dir_times;
444 @@ -129,6 +130,7 @@ int set_file_attrs(char *fname, struct f
447 int change_uid, change_gid;
448 + time_t atime, mtime;
449 mode_t new_mode = file->mode;
452 @@ -148,18 +150,33 @@ int set_file_attrs(char *fname, struct f
456 + /* This code must be the first update in the function due to
457 + * how it uses the "updated" variable. */
458 if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
459 flags |= ATTRS_SKIP_MTIME;
460 + if (!preserve_atimes || S_ISDIR(st->st_mode))
461 + flags |= ATTRS_SKIP_ATIME;
462 if (!(flags & ATTRS_SKIP_MTIME)
463 && cmp_time(st->st_mtime, file->modtime) != 0) {
464 - int ret = set_modtime(fname, file->modtime, st->st_mode);
465 + mtime = file->modtime;
468 + mtime = st->st_mtime;
469 + if (!(flags & ATTRS_SKIP_ATIME)
470 + && cmp_time(st->st_atime, file->atime) != 0) {
471 + atime = file->atime;
474 + atime = st->st_atime;
476 + int ret = set_times(fname, mtime, atime, st->st_mode);
478 rsyserr(FERROR, errno, "failed to set times on %s",
482 - if (ret == 0) /* ret == 1 if symlink could not be set */
484 + if (ret > 0) /* ret == 1 if symlink could not be set */
488 change_uid = am_root && preserve_uid && st->st_uid != file->uid;
492 #define XMIT_HAS_IDEV_DATA (1<<9)
493 #define XMIT_SAME_DEV (1<<10)
494 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
495 +#define XMIT_SAME_ATIME (1<<12)
497 /* These flags are used in the live flist data. */
501 #define ATTRS_REPORT (1<<0)
502 #define ATTRS_SKIP_MTIME (1<<1)
503 +#define ATTRS_SKIP_ATIME (1<<2)
506 #define NORMAL_FLUSH 0
507 @@ -531,9 +533,12 @@ struct file_struct {
511 - uchar flags; /* this item MUST remain last */
512 + time_t atime; /* this MUST be second to last */
513 + uchar fl4g5; /* this item MUST remain last */
516 +#define FFLAGS(f) ((uchar*)(f))[file_struct_len-1]
519 * Start the flist array at FLIST_START entries and grow it
520 * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
523 @@ -328,8 +328,9 @@ to the detailed description below for a
524 --devices preserve device files (super-user only)
525 --specials preserve special files
526 -D same as --devices --specials
527 - -t, --times preserve times
528 - -O, --omit-dir-times omit directories when preserving times
529 + -t, --times preserve modify times
530 + -O, --omit-dir-times omit directories when preserving mod-times
531 + -U, --atimes preserve access (use) times
532 --super receiver attempts super-user activities
533 -S, --sparse handle sparse files efficiently
534 -n, --dry-run show what would have been transferred
535 @@ -869,6 +870,12 @@ it is preserving modification times (see
536 the directories on the receiving side, it is a good idea to use bf(-O).
537 This option is inferred if you use bf(--backup) without bf(--backup-dir).
539 +dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the
540 +destination files to the same value as the source files. Note that the
541 +reading of the source file may update the atime of the source files, so
542 +repeated rsync runs with --atimes may be needed if you want to force the
543 +access-time values to be 100% identical on the two systems.
545 dit(bf(--super)) This tells the receiving side to attempt super-user
546 activities even if the receiving rsync wasn't run by the super-user. These
547 activities include: preserving users via the bf(--owner) option, preserving
548 @@ -1390,7 +1397,7 @@ with older versions of rsync, but that a
551 The "%i" escape has a cryptic output that is 9 letters long. The general
552 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
553 +format is like the string bf(YXcstpogu), where bf(Y) is replaced by the
554 type of update being done, bf(X) is replaced by the file-type, and the
555 other letters represent attributes that may be output if they are being
557 @@ -1430,7 +1437,7 @@ quote(itemization(
558 by the file transfer.
559 it() A bf(t) means the modification time is different and is being updated
560 to the sender's value (requires bf(--times)). An alternate value of bf(T)
561 - means that the time will be set to the transfer time, which happens
562 + means that the modify time will be set to the transfer time, which happens
563 anytime a symlink is transferred, or when a file or device is transferred
565 it() A bf(p) means the permissions are different and are being updated to
566 @@ -1439,7 +1446,10 @@ quote(itemization(
567 sender's value (requires bf(--owner) and super-user privileges).
568 it() A bf(g) means the group is different and is being updated to the
569 sender's value (requires bf(--group) and the authority to set the group).
570 - it() The bf(z) slot is reserved for future use.
571 + it() A bf(u) means the access (use) time is different and is being updated to
572 + the sender's value (requires bf(--atimes)). An alternate value of bf(U)
573 + means that the access time will be set to the transfer time, which happens
574 + when a symlink or directory is updated.
577 One other output is possible: when deleting files, the "%i" will output
580 @@ -41,6 +41,7 @@ extern int do_progress;
583 extern int write_batch;
584 +extern unsigned int file_struct_len;
585 extern struct stats stats;
586 extern struct file_list *the_file_list;
587 extern char *stdout_format;
588 @@ -373,7 +374,7 @@ void send_files(struct file_list *flist,
589 rprintf(FINFO, "sender finished %s\n", fname);
591 /* Flag that we actually sent this entry. */
592 - file->flags |= FLAG_SENT;
593 + FFLAGS(file) |= FLAG_SENT;
595 make_backups = save_make_backups;
597 --- old/testsuite/atimes.test
598 +++ new/testsuite/atimes.test
602 +# Test rsync copying atimes
604 +. "$suitedir/rsync.fns"
610 +touch "$fromdir/foo"
611 +touch -a -t 200102031717.42 "$fromdir/foo"
615 +checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
617 +# The script would have aborted on error, so getting here means we've won.
619 --- old/testsuite/rsync.fns
620 +++ new/testsuite/rsync.fns
621 @@ -66,7 +66,7 @@ printmsg() {
625 - find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
626 + find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
630 @@ -184,6 +184,10 @@ checkit() {
631 # We can just write everything to stdout/stderr, because the
632 # wrapper hides it unless there is a problem.
634 + if test x$TLS_ARGS = x--atime; then
635 + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
638 echo "Running: \"$1\""
641 @@ -191,10 +195,13 @@ checkit() {
645 + if test x$TLS_ARGS != x--atime; then
646 + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
650 echo "check how the directory listings compare with diff:"
652 - ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
653 ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
654 diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
664 #define PROGRAM "tls"
666 @@ -43,6 +44,8 @@ int read_only = 1;
668 int preserve_perms = 0;
670 +static int display_atime = 0;
672 static void failed(char const *what, char const *where)
674 fprintf(stderr, PROGRAM ": %s %s: %s\n",
675 @@ -50,12 +53,29 @@ static void failed(char const *what, cha
679 +static void storetime(char *dest, time_t t, size_t destsize)
682 + struct tm *mt = gmtime(&t);
684 + snprintf(dest, destsize,
685 + "%04d-%02d-%02d %02d:%02d:%02d ",
686 + (int)mt->tm_year + 1900,
687 + (int)mt->tm_mon + 1,
693 + strlcpy(dest, " ", destsize);
696 static void list_file(const char *fname)
699 char permbuf[PERMSTRING_SIZE];
706 if (do_lstat(fname, &buf) < 0)
707 @@ -88,19 +108,8 @@ static void list_file(const char *fname)
709 permstring(permbuf, buf.st_mode);
711 - if (buf.st_mtime) {
712 - mt = gmtime(&buf.st_mtime);
714 - snprintf(datebuf, sizeof datebuf,
715 - "%04d-%02d-%02d %02d:%02d:%02d",
716 - (int)mt->tm_year + 1900,
717 - (int)mt->tm_mon + 1,
723 - strlcpy(datebuf, " ", sizeof datebuf);
724 + storetime(mtimebuf, buf.st_mtime, sizeof mtimebuf);
725 + storetime(atimebuf, buf.st_atime, sizeof atimebuf);
727 /* TODO: Perhaps escape special characters in fname? */
729 @@ -111,23 +120,55 @@ static void list_file(const char *fname)
730 (long)minor(buf.st_rdev));
731 } else /* NB: use double for size since it might not fit in a long. */
732 printf("%12.0f", (double)buf.st_size);
733 - printf(" %6ld.%-6ld %6ld %s %s%s\n",
734 + printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
735 (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
736 - datebuf, fname, linkbuf);
737 + mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "",
741 +static struct poptOption long_options[] = {
742 + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
743 + {"atime", 'u', POPT_ARG_NONE, &display_atime, 0, 0, 0},
744 + {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
748 +static void tls_usage(int ret)
750 + fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
751 + "Trivial file listing program for portably checking rsync\n");
756 main(int argc, char *argv[])
759 - fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
760 - "Trivial file listing program for portably checking rsync\n");
764 + const char **extra_args;
767 - for (argv++; *argv; argv++) {
769 + pc = poptGetContext(PROGRAM, argc, (const char **)argv,
771 + while ((opt = poptGetNextOpt(pc)) != -1) {
778 + poptBadOption(pc, POPT_BADOPTION_NOALIAS),
779 + poptStrerror(opt));
784 + extra_args = poptGetArgs(pc);
785 + if (*extra_args == NULL)
788 + for (; *extra_args; extra_args++)
789 + list_file(*extra_args);
790 + poptFreeContext(pc);
796 @@ -121,7 +121,7 @@ NORETURN void overflow_exit(char *str)
797 exit_cleanup(RERR_MALLOC);
800 -int set_modtime(char *fname, time_t modtime, mode_t mode)
801 +int set_times(char *fname, time_t modtime, time_t atime, mode_t mode)
803 #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
805 @@ -129,9 +129,13 @@ int set_modtime(char *fname, time_t modt
809 - rprintf(FINFO, "set modtime of %s to (%ld) %s",
810 + char mtimebuf[200];
812 + strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
814 + "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
815 fname, (long)modtime,
816 - asctime(localtime(&modtime)));
817 + mtimebuf, (long)atime, timestring(atime));
821 @@ -140,7 +144,7 @@ int set_modtime(char *fname, time_t modt
825 - t[0].tv_sec = time(NULL);
826 + t[0].tv_sec = atime;
828 t[1].tv_sec = modtime;
830 @@ -151,12 +155,12 @@ int set_modtime(char *fname, time_t modt
831 return utimes(fname, t);
832 #elif defined HAVE_UTIMBUF
834 - tbuf.actime = time(NULL);
835 + tbuf.actime = atime;
836 tbuf.modtime = modtime;
837 return utime(fname,&tbuf);
838 #elif defined HAVE_UTIME
843 return utime(fname,t);