Fixed failing hunks.
[rsync/rsync-patches.git] / atimes.diff
1 After applying this patch, run these commands for a successful build:
2
3     ./prepare-source
4     ./configure                      (optional if already run)
5     make
6
7
8 --- old/flist.c
9 +++ new/flist.c
10 @@ -51,6 +51,7 @@ extern int preserve_devices;
11  extern int preserve_specials;
12  extern int preserve_uid;
13  extern int preserve_gid;
14 +extern int preserve_atimes;
15  extern int relative_paths;
16  extern int implied_dirs;
17  extern int prune_empty_dirs;
18 @@ -85,7 +86,13 @@ void init_flist(void)
19         struct file_struct f;
20  
21         /* Figure out how big the file_struct is without trailing padding */
22 -       file_struct_len = offsetof(struct file_struct, flags) + sizeof f.flags;
23 +       if (preserve_atimes)
24 +               file_struct_len = offsetof(struct file_struct, fl4g5);
25 +       else
26 +               file_struct_len = offsetof(struct file_struct, atime);
27 +       /* The "flags" uchar is no longer accessed directly, so I
28 +        * mangled the name to fl4g5 as a reminder. */
29 +       file_struct_len += sizeof f.fl4g5;
30         checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
31  }
32  
33 @@ -141,16 +148,18 @@ static void list_file_entry(struct file_
34  
35  #ifdef SUPPORT_LINKS
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",
39                         permbuf,
40                         (double)f->length, timestring(f->modtime),
41 +                       preserve_atimes ? timestring(f->atime) : "",
42                         f_name(f, NULL), f->u.link);
43         } else
44  #endif
45         {
46 -               rprintf(FINFO, "%s %11.0f %s %s\n",
47 +               rprintf(FINFO, "%s %11.0f %s %s %s\n",
48                         permbuf,
49                         (double)f->length, timestring(f->modtime),
50 +                       preserve_atimes ? timestring(f->atime) : "",
51                         f_name(f, NULL));
52         }
53  }
54 @@ -312,6 +321,7 @@ static void send_file_entry(struct file_
55  {
56         unsigned short flags;
57         static time_t modtime;
58 +       static time_t atime;
59         static mode_t mode;
60         static int64 dev;
61         static dev_t rdev;
62 @@ -327,7 +337,7 @@ static void send_file_entry(struct file_
63  
64         if (!file) {
65                 write_byte(f, 0);
66 -               modtime = 0, mode = 0;
67 +               modtime = 0, atime = 0, mode = 0;
68                 dev = 0, rdev = makedev(0, 0);
69                 rdev_major = 0;
70                 uid = 0, gid = 0;
71 @@ -339,7 +349,7 @@ static void send_file_entry(struct file_
72  
73         f_name(file, fname);
74  
75 -       flags = file->flags & XMIT_TOP_DIR;
76 +       flags = FFLAGS(file) & XMIT_TOP_DIR;
77  
78         if (file->mode == mode)
79                 flags |= XMIT_SAME_MODE;
80 @@ -375,6 +385,12 @@ static void send_file_entry(struct file_
81                 flags |= XMIT_SAME_TIME;
82         else
83                 modtime = file->modtime;
84 +       if (preserve_atimes && !S_ISDIR(mode)) {
85 +               if (file->atime == atime)
86 +                       flags |= XMIT_SAME_ATIME;
87 +               else
88 +                       atime = file->atime;
89 +       }
90  
91  #ifdef SUPPORT_HARD_LINKS
92         if (file->link_u.idev) {
93 @@ -428,6 +444,8 @@ static void send_file_entry(struct file_
94                 write_int(f, modtime);
95         if (!(flags & XMIT_SAME_MODE))
96                 write_int(f, to_wire_mode(mode));
97 +       if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
98 +               write_int(f, atime);
99         if (preserve_uid && !(flags & XMIT_SAME_UID)) {
100                 if (!numeric_ids)
101                         add_uid(uid);
102 @@ -496,6 +514,7 @@ static struct file_struct *receive_file_
103                                               unsigned short flags, int f)
104  {
105         static time_t modtime;
106 +       static time_t atime;
107         static mode_t mode;
108         static int64 dev;
109         static dev_t rdev;
110 @@ -514,7 +533,7 @@ static struct file_struct *receive_file_
111         struct file_struct *file;
112  
113         if (!flist) {
114 -               modtime = 0, mode = 0;
115 +               modtime = 0, atime = 0, mode = 0;
116                 dev = 0, rdev = makedev(0, 0);
117                 rdev_major = 0;
118                 uid = 0, gid = 0;
119 @@ -570,6 +589,8 @@ static struct file_struct *receive_file_
120                 modtime = (time_t)read_int(f);
121         if (!(flags & XMIT_SAME_MODE))
122                 mode = from_wire_mode(read_int(f));
123 +       if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
124 +               atime = (time_t)read_int(f);
125  
126         if (chmod_modes && !S_ISLNK(mode))
127                 mode = tweak_mode(mode, chmod_modes);
128 @@ -625,6 +646,8 @@ static struct file_struct *receive_file_
129         file->mode = mode;
130         file->uid = uid;
131         file->gid = gid;
132 +       if (preserve_atimes)
133 +               file->atime = atime;
134  
135         if (dirname_len) {
136                 file->dirname = lastdir = bp;
137 @@ -650,12 +673,12 @@ static struct file_struct *receive_file_
138                             && lastname[del_hier_name_len-1] == '.'
139                             && lastname[del_hier_name_len-2] == '/')
140                                 del_hier_name_len -= 2;
141 -                       file->flags |= FLAG_TOP_DIR | FLAG_DEL_HERE;
142 +                       FFLAGS(file) |= FLAG_TOP_DIR | FLAG_DEL_HERE;
143                 } else if (in_del_hier) {
144                         if (!relative_paths || !del_hier_name_len
145                          || (l1 >= del_hier_name_len
146                           && lastname[del_hier_name_len] == '/'))
147 -                               file->flags |= FLAG_DEL_HERE;
148 +                               FFLAGS(file) |= FLAG_DEL_HERE;
149                         else
150                                 in_del_hier = 0;
151                 }
152 @@ -871,12 +894,14 @@ struct file_struct *make_file(char *fnam
153         memset(bp, 0, file_struct_len);
154         bp += file_struct_len;
155  
156 -       file->flags = flags;
157 +       FFLAGS(file) = flags;
158         file->modtime = st.st_mtime;
159         file->length = st.st_size;
160         file->mode = st.st_mode;
161         file->uid = st.st_uid;
162         file->gid = st.st_gid;
163 +       if (preserve_atimes)
164 +               file->atime = st.st_atime;
165  
166  #ifdef SUPPORT_HARD_LINKS
167         if (flist && flist->hlink_pool) {
168 @@ -989,7 +1014,7 @@ static void send_if_directory(int f, str
169         char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
170  
171         if (S_ISDIR(file->mode)
172 -           && !(file->flags & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
173 +           && !(FFLAGS(file) & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
174                 void *save_filters;
175                 unsigned int len = strlen(fbuf);
176                 if (len > 1 && fbuf[len-1] == '/')
177 @@ -1595,8 +1620,9 @@ static void clean_flist(struct file_list
178                         }
179                         /* Make sure we don't lose track of a user-specified
180                          * top directory. */
181 -                       flist->files[keep]->flags |= flist->files[drop]->flags
182 -                                                  & (FLAG_TOP_DIR|FLAG_DEL_HERE);
183 +                       FFLAGS(flist->files[keep])
184 +                           |= FFLAGS(flist->files[drop])
185 +                            & (FLAG_TOP_DIR|FLAG_DEL_HERE);
186  
187                         clear_file(flist->files[drop], flist);
188  
189 @@ -1720,7 +1746,7 @@ static void output_flist(struct file_lis
190                         file->dirname ? file->dirname : "",
191                         file->dirname ? "/" : "", NS(file->basename),
192                         S_ISDIR(file->mode) ? "/" : "", (int)file->mode,
193 -                       (double)file->length, uidbuf, gidbuf, file->flags);
194 +                       (double)file->length, uidbuf, gidbuf, FFLAGS(file));
195         }
196  }
197  
198 --- old/generator.c
199 +++ new/generator.c
200 @@ -45,6 +45,7 @@ extern int preserve_perms;
201  extern int preserve_uid;
202  extern int preserve_gid;
203  extern int preserve_times;
204 +extern int preserve_atimes;
205  extern int omit_dir_times;
206  extern int delete_mode;
207  extern int delete_before;
208 @@ -91,6 +92,7 @@ extern dev_t filesystem_dev;
209  extern char *backup_dir;
210  extern char *backup_suffix;
211  extern int backup_suffix_len;
212 +extern unsigned int file_struct_len;
213  extern struct file_list *the_file_list;
214  extern struct filter_list_struct server_filter_list;
215  
216 @@ -185,7 +187,7 @@ static int delete_item(char *fname, int 
217         for (j = dirlist->count; j--; ) {
218                 struct file_struct *fp = dirlist->files[j];
219  
220 -               if (fp->flags & FLAG_MOUNT_POINT)
221 +               if (FFLAGS(fp) & FLAG_MOUNT_POINT)
222                         continue;
223  
224                 strlcpy(p, fp->basename, remainder);
225 @@ -263,7 +265,7 @@ static void delete_in_dir(struct file_li
226         filt_array[cur_depth] = push_local_filters(fbuf, dlen);
227  
228         if (one_file_system) {
229 -               if (file->flags & FLAG_TOP_DIR)
230 +               if (FFLAGS(file) & FLAG_TOP_DIR)
231                         filesystem_dev = stp->st_dev;
232                 else if (filesystem_dev != stp->st_dev)
233                         return;
234 @@ -275,7 +277,7 @@ static void delete_in_dir(struct file_li
235          * from the filesystem. */
236         for (i = dirlist->count; i--; ) {
237                 struct file_struct *fp = dirlist->files[i];
238 -               if (!fp->basename || fp->flags & FLAG_MOUNT_POINT)
239 +               if (!fp->basename || FFLAGS(fp) & FLAG_MOUNT_POINT)
240                         continue;
241                 if (flist_find(flist, fp) < 0) {
242                         f_name(fp, delbuf);
243 @@ -301,11 +303,11 @@ static void do_delete_pass(struct file_l
244         for (j = 0; j < flist->count; j++) {
245                 struct file_struct *file = flist->files[j];
246  
247 -               if (!(file->flags & FLAG_DEL_HERE))
248 +               if (!(FFLAGS(file) & FLAG_DEL_HERE))
249                         continue;
250  
251                 f_name(file, fbuf);
252 -               if (verbose > 1 && file->flags & FLAG_TOP_DIR)
253 +               if (verbose > 1 && FFLAGS(file) & FLAG_TOP_DIR)
254                         rprintf(FINFO, "deleting in %s\n", fbuf);
255  
256                 if (link_stat(fbuf, &st, keep_dirlinks) < 0
257 @@ -349,6 +351,9 @@ void itemize(struct file_struct *file, i
258                      && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
259                     || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
260                         iflags |= ITEM_REPORT_TIME;
261 +               if (preserve_atimes && !S_ISDIR(file->mode) && !S_ISLNK(file->mode)
262 +                && cmp_time(file->atime, st->st_atime) != 0)
263 +                       iflags |= ITEM_REPORT_ATIME;
264                 if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
265                         iflags |= ITEM_REPORT_PERMS;
266                 if (preserve_uid && am_root && file->uid != st->st_uid)
267 @@ -550,7 +555,7 @@ static int find_fuzzy(struct file_struct
268                 uint32 dist;
269  
270                 if (!S_ISREG(fp->mode) || !fp->length
271 -                   || fp->flags & FLAG_NO_FUZZY)
272 +                   || FFLAGS(fp) & FLAG_NO_FUZZY)
273                         continue;
274  
275                 name = fp->basename;
276 @@ -659,6 +664,8 @@ static int try_dests_reg(struct file_str
277                                           itemizing && verbose > 1,
278                                           code) < 0)
279                                 goto try_a_copy;
280 +                       if (preserve_atimes)
281 +                               set_file_attrs(fname, file, stp, 0);
282                         if (preserve_hard_links && file->link_u.links)
283                                 hard_link_cluster(file, ndx, itemizing, code);
284                 } else if (itemizing)
285 @@ -906,7 +913,7 @@ static void recv_generator(char *fname, 
286                     && verbose && code && f_out != -1)
287                         rprintf(code, "%s/\n", fname);
288                 if (delete_during && f_out != -1 && !phase && dry_run < 2
289 -                   && (file->flags & FLAG_DEL_HERE))
290 +                   && (FFLAGS(file) & FLAG_DEL_HERE))
291                         delete_in_dir(the_file_list, fname, file, &st);
292                 return;
293         }
294 @@ -1188,7 +1195,7 @@ static void recv_generator(char *fname, 
295         if (fuzzy_dirlist) {
296                 int j = flist_find(fuzzy_dirlist, file);
297                 if (j >= 0) /* don't use changing file as future fuzzy basis */
298 -                       fuzzy_dirlist->files[j]->flags |= FLAG_NO_FUZZY;
299 +                       FFLAGS(fuzzy_dirlist->files[j]) |= FLAG_NO_FUZZY;
300         }
301  
302         /* open the file */
303 --- old/hlink.c
304 +++ new/hlink.c
305 @@ -26,6 +26,7 @@ extern int link_dest;
306  extern int make_backups;
307  extern int log_format_has_i;
308  extern char *basis_dir[];
309 +extern unsigned int file_struct_len;
310  extern struct file_list *the_file_list;
311  
312  #ifdef SUPPORT_HARD_LINKS
313 @@ -86,10 +87,10 @@ static void link_idev_data(void)
314                         FPTR(cur)->link_u.links = pool_talloc(hlink_pool,
315                             struct hlink, 1, "hlink_list");
316  
317 -                       FPTR(head)->flags |= FLAG_HLINK_TOL;
318 +                       FFLAGS(FPTR(head)) |= FLAG_HLINK_TOL;
319                         FPTR(cur)->F_HLINDEX = to;
320                         FPTR(cur)->F_NEXT = head;
321 -                       FPTR(cur)->flags |= FLAG_HLINK_EOL;
322 +                       FFLAGS(FPTR(cur)) |= FLAG_HLINK_EOL;
323                         hlink_list[to++] = head;
324                 } else
325                         FPTR(cur)->link_u.links = NULL;
326 @@ -175,7 +176,7 @@ int hard_link_check(struct file_struct *
327  {
328  #ifdef SUPPORT_HARD_LINKS
329         int head;
330 -       if (skip && !(file->flags & FLAG_HLINK_EOL))
331 +       if (skip && !(FFLAGS(file) & FLAG_HLINK_EOL))
332                 head = hlink_list[file->F_HLINDEX] = file->F_NEXT;
333         else
334                 head = hlink_list[file->F_HLINDEX];
335 @@ -270,8 +271,8 @@ void hard_link_cluster(struct file_struc
336         file->F_HLINDEX = FINISHED_LINK;
337         if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
338                 return;
339 -       if (!(file->flags & FLAG_HLINK_TOL)) {
340 -               while (!(file->flags & FLAG_HLINK_EOL)) {
341 +       if (!(FFLAGS(file) & FLAG_HLINK_TOL)) {
342 +               while (!(FFLAGS(file) & FLAG_HLINK_EOL)) {
343                         ndx = file->F_NEXT;
344                         file = FPTR(ndx);
345                 }
346 @@ -286,6 +287,6 @@ void hard_link_cluster(struct file_struc
347                 maybe_hard_link(file, ndx, hlink2, statret, &st2,
348                                 hlink1, &st1, itemizing, code);
349                 file->F_HLINDEX = FINISHED_LINK;
350 -       } while (!(file->flags & FLAG_HLINK_EOL));
351 +       } while (!(FFLAGS(file) & FLAG_HLINK_EOL));
352  #endif
353  }
354 --- old/log.c
355 +++ new/log.c
356 @@ -42,6 +42,7 @@ extern int msg_fd_out;
357  extern int allow_8bit_chars;
358  extern int protocol_version;
359  extern int preserve_times;
360 +extern int preserve_atimes;
361  extern int log_format_has_i;
362  extern int log_format_has_o_or_i;
363  extern int daemon_log_format_has_o_or_i;
364 @@ -608,7 +609,8 @@ static void log_formatted(enum logcode c
365                         n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
366                         n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
367                         n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
368 -                       n[8] = '.';
369 +                       n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.'
370 +                            : S_ISLNK(file->mode) ? 'U' : 'u';
371                         n[9] = '\0';
372  
373                         if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
374 --- old/options.c
375 +++ new/options.c
376 @@ -52,6 +52,7 @@ int preserve_uid = 0;
377  int preserve_gid = 0;
378  int preserve_times = 0;
379  int omit_dir_times = 0;
380 +int preserve_atimes = 0;
381  int update_only = 0;
382  int cvs_exclude = 0;
383  int dry_run = 0;
384 @@ -299,8 +300,9 @@ void usage(enum logcode F)
385    rprintf(F,"     --devices               preserve device files (super-user only)\n");
386    rprintf(F,"     --specials              preserve special files\n");
387    rprintf(F," -D                          same as --devices --specials\n");
388 -  rprintf(F," -t, --times                 preserve times\n");
389 -  rprintf(F," -O, --omit-dir-times        omit directories when preserving times\n");
390 +  rprintf(F," -t, --times                 preserve modify times\n");
391 +  rprintf(F," -O, --omit-dir-times        omit directories when preserving modify times\n");
392 +  rprintf(F," -U, --atimes                preserve access (use) times\n");
393    rprintf(F,"     --super                 receiver attempts super-user activities\n");
394    rprintf(F," -S, --sparse                handle sparse files efficiently\n");
395    rprintf(F," -n, --dry-run               show what would have been transferred\n");
396 @@ -411,6 +413,9 @@ static struct poptOption long_options[] 
397    {"times",           't', POPT_ARG_VAL,    &preserve_times, 1, 0, 0 },
398    {"no-times",         0,  POPT_ARG_VAL,    &preserve_times, 0, 0, 0 },
399    {"no-t",             0,  POPT_ARG_VAL,    &preserve_times, 0, 0, 0 },
400 +  {"atimes",          'U', POPT_ARG_VAL,    &preserve_atimes, 1, 0, 0 },
401 +  {"no-atimes",        0,  POPT_ARG_VAL,    &preserve_atimes, 0, 0, 0 },
402 +  {"no-k",             0,  POPT_ARG_VAL,    &preserve_atimes, 0, 0, 0 },
403    {"omit-dir-times",  'O', POPT_ARG_VAL,    &omit_dir_times, 2, 0, 0 },
404    {"modify-window",    0,  POPT_ARG_INT,    &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
405    {"super",            0,  POPT_ARG_VAL,    &am_root, 2, 0, 0 },
406 @@ -1510,6 +1515,8 @@ void server_options(char **args,int *arg
407                 argstr[x++] = 'D';
408         if (preserve_times)
409                 argstr[x++] = 't';
410 +       if (preserve_atimes)
411 +               argstr[x++] = 'U';
412         if (preserve_perms)
413                 argstr[x++] = 'p';
414         else if (preserve_executability && am_sender)
415 --- old/rsync.c
416 +++ new/rsync.c
417 @@ -35,6 +35,7 @@ extern int dry_run;
418  extern int daemon_log_format_has_i;
419  extern int preserve_perms;
420  extern int preserve_executability;
421 +extern int preserve_atimes;
422  extern int preserve_times;
423  extern int omit_dir_times;
424  extern int am_root;
425 @@ -128,6 +129,7 @@ int set_file_attrs(char *fname, struct f
426         int updated = 0;
427         STRUCT_STAT st2;
428         int change_uid, change_gid;
429 +       time_t atime, mtime;
430  
431         if (!st) {
432                 if (dry_run)
433 @@ -146,18 +148,33 @@ int set_file_attrs(char *fname, struct f
434                 }
435         }
436  
437 +       /* This code must be the first update in the function due to
438 +        * how it uses the "updated" variable. */
439         if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
440                 flags |= ATTRS_SKIP_MTIME;
441 +       if (!preserve_atimes || S_ISDIR(st->st_mode))
442 +               flags |= ATTRS_SKIP_ATIME;
443         if (!(flags & ATTRS_SKIP_MTIME)
444             && cmp_time(st->st_mtime, file->modtime) != 0) {
445 -               int ret = set_modtime(fname, file->modtime, st->st_mode);
446 +               mtime = file->modtime;
447 +               updated = 1;
448 +       } else
449 +               mtime = st->st_mtime;
450 +       if (!(flags & ATTRS_SKIP_ATIME)
451 +           && cmp_time(st->st_atime, file->atime) != 0) {
452 +               atime = file->atime;
453 +               updated = 1;
454 +       } else
455 +               atime = st->st_atime;
456 +       if (updated) {
457 +               int ret = set_times(fname, mtime, atime, st->st_mode);
458                 if (ret < 0) {
459                         rsyserr(FERROR, errno, "failed to set times on %s",
460                                 full_fname(fname));
461                         return 0;
462                 }
463 -               if (ret == 0) /* ret == 1 if symlink could not be set */
464 -                       updated = 1;
465 +               if (ret > 0) /* ret == 1 if symlink could not be set */
466 +                       updated = 0;
467         }
468  
469         change_uid = am_root && preserve_uid && st->st_uid != file->uid;
470 --- old/rsync.h
471 +++ new/rsync.h
472 @@ -54,6 +54,7 @@
473  #define XMIT_HAS_IDEV_DATA (1<<9)
474  #define XMIT_SAME_DEV (1<<10)
475  #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
476 +#define XMIT_SAME_ATIME (1<<12)
477  
478  /* These flags are used in the live flist data. */
479  
480 @@ -119,6 +120,7 @@
481  
482  #define ATTRS_REPORT           (1<<0)
483  #define ATTRS_SKIP_MTIME       (1<<1)
484 +#define ATTRS_SKIP_ATIME       (1<<2)
485  
486  #define FULL_FLUSH     1
487  #define NORMAL_FLUSH   0
488 @@ -135,6 +137,7 @@
489  #define FNAMECMP_FUZZY         0x83
490  
491  /* For use by the itemize_changes code */
492 +#define ITEM_REPORT_ATIME (1<<0)
493  #define ITEM_REPORT_CHECKSUM (1<<1)
494  #define ITEM_REPORT_SIZE (1<<2)
495  #define ITEM_REPORT_TIME (1<<3)
496 @@ -520,9 +523,12 @@ struct file_struct {
497         uid_t uid;
498         gid_t gid;
499         mode_t mode;
500 -       uchar flags;    /* this item MUST remain last */
501 +       time_t atime;   /* this MUST be second to last */
502 +       uchar fl4g5;    /* this item MUST remain last */
503  };
504  
505 +#define FFLAGS(f) ((uchar*)(f))[file_struct_len-1]
506 +
507  /*
508   * Start the flist array at FLIST_START entries and grow it
509   * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
510 --- old/rsync.yo
511 +++ new/rsync.yo
512 @@ -325,8 +325,9 @@ to the detailed description below for a 
513       --devices               preserve device files (super-user only)
514       --specials              preserve special files
515   -D                          same as --devices --specials
516 - -t, --times                 preserve times
517 - -O, --omit-dir-times        omit directories when preserving times
518 + -t, --times                 preserve modify times
519 + -O, --omit-dir-times        omit directories when preserving mod-times
520 + -U, --atimes                preserve access (use) times
521       --super                 receiver attempts super-user activities
522   -S, --sparse                handle sparse files efficiently
523   -n, --dry-run               show what would have been transferred
524 @@ -814,6 +815,12 @@ it is preserving modification times (see
525  the directories on the receiving side, it is a good idea to use bf(-O).
526  This option is inferred if you use bf(--backup) without bf(--backup-dir).
527  
528 +dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the
529 +destination files to the same value as the source files.  Note that the
530 +reading of the source file may update the atime of the source files, so
531 +repeated rsync runs with --atimes may be needed if you want to force the
532 +access-time values to be 100% identical on the two systems.
533 +
534  dit(bf(--super)) This tells the receiving side to attempt super-user
535  activities even if the receiving rsync wasn't run by the super-user.  These
536  activities include: preserving users via the bf(--owner) option, preserving
537 @@ -1322,7 +1329,7 @@ with older versions of rsync, but that a
538  verbose messages).
539  
540  The "%i" escape has a cryptic output that is 9 letters long.  The general
541 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
542 +format is like the string bf(YXcstpogu), where bf(Y) is replaced by the
543  type of update being done, bf(X) is replaced by the file-type, and the
544  other letters represent attributes that may be output if they are being
545  modified.
546 @@ -1362,7 +1369,7 @@ quote(itemize(
547    by the file transfer.
548    it() A bf(t) means the modification time is different and is being updated
549    to the sender's value (requires bf(--times)).  An alternate value of bf(T)
550 -  means that the time will be set to the transfer time, which happens
551 +  means that the modify time will be set to the transfer time, which happens
552    anytime a symlink is transferred, or when a file or device is transferred
553    without bf(--times).
554    it() A bf(p) means the permissions are different and are being updated to
555 @@ -1371,7 +1378,10 @@ quote(itemize(
556    sender's value (requires bf(--owner) and super-user privileges).
557    it() A bf(g) means the group is different and is being updated to the
558    sender's value (requires bf(--group) and the authority to set the group).
559 -  it() The bf(z) slot is reserved for future use.
560 +  it() A bf(u) means the access (use) time is different and is being updated to
561 +  the sender's value (requires bf(--atimes)).  An alternate value of bf(U)
562 +  means that the access time will be set to the transfer time, which happens
563 +  when a symlink or directory is updated.
564  ))
565  
566  One other output is possible:  when deleting files, the "%i" will output
567 --- old/sender.c
568 +++ new/sender.c
569 @@ -38,6 +38,7 @@ extern int do_progress;
570  extern int inplace;
571  extern int batch_fd;
572  extern int write_batch;
573 +extern unsigned int file_struct_len;
574  extern struct stats stats;
575  extern struct file_list *the_file_list;
576  extern char *log_format;
577 @@ -126,7 +127,7 @@ void successful_send(int ndx)
578  
579         file = the_file_list->files[ndx];
580         /* The generator might tell us about symlinks we didn't send. */
581 -       if (!(file->flags & FLAG_SENT) && !S_ISLNK(file->mode))
582 +       if (!(FFLAGS(file) & FLAG_SENT) && !S_ISLNK(file->mode))
583                 return;
584         if (file->dir.root) {
585                 offset = stringjoin(fname, sizeof fname,
586 @@ -370,7 +371,7 @@ void send_files(struct file_list *flist,
587                         rprintf(FINFO, "sender finished %s\n", fname);
588  
589                 /* Flag that we actually sent this entry. */
590 -               file->flags |= FLAG_SENT;
591 +               FFLAGS(file) |= FLAG_SENT;
592         }
593         make_backups = save_make_backups;
594  
595 --- old/testsuite/atimes.test
596 +++ new/testsuite/atimes.test
597 @@ -0,0 +1,19 @@
598 +#! /bin/sh
599 +
600 +# Test rsync copying atimes
601 +
602 +. "$suitedir/rsync.fns"
603 +
604 +set -x
605 +
606 +mkdir "$fromdir"
607 +
608 +touch "$fromdir/foo"
609 +touch -a -t 200102031717.42 "$fromdir/foo"
610 +
611 +TLS_ARGS=--atime
612 +
613 +checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
614 +
615 +# The script would have aborted on error, so getting here means we've won.
616 +exit 0
617 --- old/testsuite/rsync.fns
618 +++ new/testsuite/rsync.fns
619 @@ -66,7 +66,7 @@ printmsg() {
620  }
621  
622  rsync_ls_lR() {
623 -    find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
624 +    find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
625  }
626  
627  check_perms() {
628 @@ -184,6 +184,10 @@ checkit() {
629      # We can just write everything to stdout/stderr, because the
630      # wrapper hides it unless there is a problem.
631  
632 +    if test x$TLS_ARGS = x--atime; then
633 +       ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
634 +    fi
635 +
636      echo "Running: \"$1\""  
637      eval "$1" 
638      status=$?
639 @@ -191,10 +195,13 @@ checkit() {
640         failed="YES";
641      fi
642  
643 +    if test x$TLS_ARGS != x--atime; then
644 +       ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
645 +    fi
646 +
647      echo "-------------"
648      echo "check how the directory listings compare with diff:"
649      echo ""
650 -    ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
651      ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
652      diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
653  
654 --- old/tls.c
655 +++ new/tls.c
656 @@ -39,6 +39,7 @@
657  
658  
659  #include "rsync.h"
660 +#include "popt.h"
661  
662  #define PROGRAM "tls"
663  
664 @@ -48,6 +49,7 @@ int read_only = 1;
665  int list_only = 0;
666  int preserve_perms = 0;
667  
668 +static int display_atime = 0;
669  
670  static void failed(char const *what, char const *where)
671  {
672 @@ -56,14 +58,29 @@ static void failed(char const *what, cha
673         exit(1);
674  }
675  
676 +static void storetime(char *dest, time_t t)
677 +{
678 +       if (t) {
679 +               struct tm *mt = gmtime(&t);
680  
681 +               sprintf(dest, "%04d-%02d-%02d %02d:%02d:%02d ",
682 +                       (int)mt->tm_year + 1900,
683 +                       (int)mt->tm_mon + 1,
684 +                       (int)mt->tm_mday,
685 +                       (int)mt->tm_hour,
686 +                       (int)mt->tm_min,
687 +                       (int)mt->tm_sec);
688 +       } else {
689 +               strcpy(dest, "                    ");
690 +       }
691 +}      
692  
693  static void list_file(const char *fname)
694  {
695         STRUCT_STAT buf;
696         char permbuf[PERMSTRING_SIZE];
697 -       struct tm *mt;
698 -       char datebuf[50];
699 +       char mtimebuf[50];
700 +       char atimebuf[50];
701         char linkbuf[4096];
702  
703         if (do_lstat(fname, &buf) < 0)
704 @@ -96,19 +113,8 @@ static void list_file(const char *fname)
705  
706         permstring(permbuf, buf.st_mode);
707  
708 -       if (buf.st_mtime) {
709 -               mt = gmtime(&buf.st_mtime);
710 -
711 -               sprintf(datebuf, "%04d-%02d-%02d %02d:%02d:%02d",
712 -                       (int)mt->tm_year + 1900,
713 -                       (int)mt->tm_mon + 1,
714 -                       (int)mt->tm_mday,
715 -                       (int)mt->tm_hour,
716 -                       (int)mt->tm_min,
717 -                       (int)mt->tm_sec);
718 -       } else {
719 -               strcpy(datebuf, "                   ");
720 -       }
721 +       storetime(mtimebuf, buf.st_mtime);
722 +       storetime(atimebuf, buf.st_atime);
723  
724         /* TODO: Perhaps escape special characters in fname? */
725  
726 @@ -119,24 +125,55 @@ static void list_file(const char *fname)
727                     (long)minor(buf.st_rdev));
728         } else /* NB: use double for size since it might not fit in a long. */
729                 printf("%12.0f", (double)buf.st_size);
730 -       printf(" %6ld.%-6ld %6ld %s %s%s\n",
731 +       printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
732                (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
733 -              datebuf, fname, linkbuf);
734 +              mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "",
735 +              fname, linkbuf);
736  }
737  
738 +static struct poptOption long_options[] = {
739 +  /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
740 +  {"atime",           'u', POPT_ARG_NONE,   &display_atime, 0,   0, 0},
741 +  {"help",            'h', POPT_ARG_NONE,   0,              'h', 0, 0},
742 +  {0,0,0,0,0,0,0}
743 +};
744 +
745 +static void tls_usage(int ret)
746 +{
747 +       fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
748 +           "Trivial file listing program for portably checking rsync\n");
749 +       exit(ret);
750 +}
751  
752  int
753  main(int argc, char *argv[])
754  {
755 -       if (argc < 2) {
756 -               fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
757 -                       "Trivial file listing program for portably checking rsync\n");
758 -               return 1;
759 +       poptContext pc;
760 +       const char **extra_args;
761 +       int opt;
762 +
763 +       pc = poptGetContext(PROGRAM, argc, (const char **)argv,
764 +                           long_options, 0);
765 +       while ((opt = poptGetNextOpt(pc)) != -1) {
766 +               switch (opt) {
767 +               case 'h':
768 +                       tls_usage(0);
769 +               default:
770 +                       fprintf(stderr,
771 +                               "%s: %s\n",
772 +                               poptBadOption(pc, POPT_BADOPTION_NOALIAS),
773 +                               poptStrerror(opt));
774 +                       tls_usage(1);
775 +               }
776         }
777  
778 -       for (argv++; *argv; argv++) {
779 -               list_file(*argv);
780 -       }
781 +       extra_args = poptGetArgs(pc);
782 +       if (*extra_args == NULL)
783 +               tls_usage(1);
784 +
785 +       for (; *extra_args; extra_args++)
786 +               list_file(*extra_args);
787 +       poptFreeContext(pc);
788  
789         return 0;
790  }
791 --- old/util.c
792 +++ new/util.c
793 @@ -126,7 +126,7 @@ void overflow_exit(char *str)
794         exit_cleanup(RERR_MALLOC);
795  }
796  
797 -int set_modtime(char *fname, time_t modtime, mode_t mode)
798 +int set_times(char *fname, time_t modtime, time_t atime, mode_t mode)
799  {
800  #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
801         if (S_ISLNK(mode))
802 @@ -134,9 +134,13 @@ int set_modtime(char *fname, time_t modt
803  #endif
804  
805         if (verbose > 2) {
806 -               rprintf(FINFO, "set modtime of %s to (%ld) %s",
807 +               char mtimebuf[200];
808 +
809 +               strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
810 +               rprintf(FINFO,
811 +                       "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
812                         fname, (long)modtime,
813 -                       asctime(localtime(&modtime)));
814 +                       mtimebuf, (long)atime, timestring(atime));
815         }
816  
817         if (dry_run)
818 @@ -145,7 +149,7 @@ int set_modtime(char *fname, time_t modt
819         {
820  #ifdef HAVE_UTIMES
821                 struct timeval t[2];
822 -               t[0].tv_sec = time(NULL);
823 +               t[0].tv_sec = atime;
824                 t[0].tv_usec = 0;
825                 t[1].tv_sec = modtime;
826                 t[1].tv_usec = 0;
827 @@ -156,12 +160,12 @@ int set_modtime(char *fname, time_t modt
828                 return utimes(fname, t);
829  #elif defined HAVE_UTIMBUF
830                 struct utimbuf tbuf;
831 -               tbuf.actime = time(NULL);
832 +               tbuf.actime = atime;
833                 tbuf.modtime = modtime;
834                 return utime(fname,&tbuf);
835  #elif defined HAVE_UTIME
836                 time_t t[2];
837 -               t[0] = time(NULL);
838 +               t[0] = atime;
839                 t[1] = modtime;
840                 return utime(fname,t);
841  #else