Fixed compilation problems that crept into the code.
[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 @@ -46,6 +46,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 @@ -79,7 +80,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 @@ -135,16 +142,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 @@ -302,6 +311,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 @@ -317,7 +327,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 @@ -327,7 +337,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 @@ -363,6 +373,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 @@ -416,6 +432,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 @@ -482,6 +500,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 @@ -500,7 +519,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 @@ -556,6 +575,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 @@ -611,6 +632,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 @@ -636,12 +659,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 @@ -858,12 +881,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 @@ -976,7 +1001,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 @@ -1586,8 +1611,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 @@ -1711,7 +1737,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 @@ -43,6 +43,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 @@ -90,6 +91,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 @@ -182,7 +184,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 @@ -260,7 +262,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 @@ -272,7 +274,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 @@ -298,11 +300,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 @@ -346,6 +348,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 @@ -549,7 +554,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 @@ -658,6 +663,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                                 if (dry_run)
284                                         file->link_u.links->link_dest_used = j + 1;
285 @@ -930,7 +937,7 @@ static void recv_generator(char *fname, 
286                                 rsyserr(FERROR, errno,
287                                         "recv_generator: mkdir %s failed",
288                                         full_fname(fname));
289 -                               file->flags |= FLAG_MISSING;
290 +                               FFLAGS(file) |= FLAG_MISSING;
291                                 if (ndx+1 < the_file_list->count
292                                  && the_file_list->files[ndx+1]->dir.depth > file->dir.depth) {
293                                         rprintf(FERROR,
294 @@ -944,7 +951,7 @@ static void recv_generator(char *fname, 
295                     && verbose && code != FNONE && f_out != -1)
296                         rprintf(code, "%s/\n", fname);
297                 if (delete_during && f_out != -1 && !phase && dry_run < 2
298 -                   && (file->flags & FLAG_DEL_HERE))
299 +                   && (FFLAGS(file) & FLAG_DEL_HERE))
300                         delete_in_dir(the_file_list, fname, file, &st);
301                 return;
302         }
303 @@ -1249,7 +1256,7 @@ static void recv_generator(char *fname, 
304         if (fuzzy_dirlist) {
305                 int j = flist_find(fuzzy_dirlist, file);
306                 if (j >= 0) /* don't use changing file as future fuzzy basis */
307 -                       fuzzy_dirlist->files[j]->flags |= FLAG_NO_FUZZY;
308 +                       FFLAGS(fuzzy_dirlist->files[j]) |= FLAG_NO_FUZZY;
309         }
310  
311         /* open the file */
312 @@ -1514,7 +1521,7 @@ void generate_files(int f_out, struct fi
313                                 continue;
314                         if (!need_retouch_dir_times && file->mode & S_IWUSR)
315                                 continue;
316 -                       if (file->flags & FLAG_MISSING) {
317 +                       if (FFLAGS(file) & FLAG_MISSING) {
318                                 int missing = file->dir.depth;
319                                 while (++i < flist->count) {
320                                         file = flist->files[i];
321 --- old/hlink.c
322 +++ new/hlink.c
323 @@ -30,6 +30,7 @@ extern int make_backups;
324  extern int remove_source_files;
325  extern int stdout_format_has_i;
326  extern char *basis_dir[];
327 +extern unsigned int file_struct_len;
328  extern struct file_list *the_file_list;
329  
330  #ifdef SUPPORT_HARD_LINKS
331 @@ -90,10 +91,10 @@ static void link_idev_data(void)
332                         FPTR(cur)->link_u.links = pool_talloc(hlink_pool,
333                             struct hlink, 1, "hlink_list");
334  
335 -                       FPTR(head)->flags |= FLAG_HLINK_TOL;
336 +                       FFLAGS(FPTR(head)) |= FLAG_HLINK_TOL;
337                         FPTR(cur)->F_HLINDEX = to;
338                         FPTR(cur)->F_NEXT = head;
339 -                       FPTR(cur)->flags |= FLAG_HLINK_EOL;
340 +                       FFLAGS(FPTR(cur)) |= FLAG_HLINK_EOL;
341                         hlink_list[to++] = head;
342                 } else
343                         FPTR(cur)->link_u.links = NULL;
344 @@ -179,7 +180,7 @@ int hard_link_check(struct file_struct *
345  {
346  #ifdef SUPPORT_HARD_LINKS
347         int head;
348 -       if (skip && !(file->flags & FLAG_HLINK_EOL))
349 +       if (skip && !(FFLAGS(file) & FLAG_HLINK_EOL))
350                 head = hlink_list[file->F_HLINDEX] = file->F_NEXT;
351         else
352                 head = hlink_list[file->F_HLINDEX];
353 @@ -287,8 +288,8 @@ void hard_link_cluster(struct file_struc
354         file->F_HLINDEX = FINISHED_LINK;
355         if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
356                 return;
357 -       if (!(file->flags & FLAG_HLINK_TOL)) {
358 -               while (!(file->flags & FLAG_HLINK_EOL)) {
359 +       if (!(FFLAGS(file) & FLAG_HLINK_TOL)) {
360 +               while (!(FFLAGS(file) & FLAG_HLINK_EOL)) {
361                         ndx = file->F_NEXT;
362                         file = FPTR(ndx);
363                 }
364 @@ -308,6 +309,6 @@ void hard_link_cluster(struct file_struc
365                         send_msg(MSG_SUCCESS, numbuf, 4);
366                 }
367                 file->F_HLINDEX = FINISHED_LINK;
368 -       } while (!(file->flags & FLAG_HLINK_EOL));
369 +       } while (!(FFLAGS(file) & FLAG_HLINK_EOL));
370  #endif
371  }
372 --- old/log.c
373 +++ new/log.c
374 @@ -37,6 +37,7 @@ extern int msg_fd_out;
375  extern int allow_8bit_chars;
376  extern int protocol_version;
377  extern int preserve_times;
378 +extern int preserve_atimes;
379  extern int stdout_format_has_i;
380  extern int stdout_format_has_o_or_i;
381  extern int logfile_format_has_i;
382 @@ -606,7 +607,8 @@ static void log_formatted(enum logcode c
383                         n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
384                         n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
385                         n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
386 -                       n[8] = '.';
387 +                       n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.'
388 +                            : S_ISLNK(file->mode) ? 'U' : 'u';
389                         n[9] = '\0';
390  
391                         if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
392 --- old/options.c
393 +++ new/options.c
394 @@ -55,6 +55,7 @@ int preserve_uid = 0;
395  int preserve_gid = 0;
396  int preserve_times = 0;
397  int omit_dir_times = 0;
398 +int preserve_atimes = 0;
399  int update_only = 0;
400  int cvs_exclude = 0;
401  int dry_run = 0;
402 @@ -309,8 +310,9 @@ void usage(enum logcode F)
403    rprintf(F,"     --devices               preserve device files (super-user only)\n");
404    rprintf(F,"     --specials              preserve special files\n");
405    rprintf(F," -D                          same as --devices --specials\n");
406 -  rprintf(F," -t, --times                 preserve times\n");
407 -  rprintf(F," -O, --omit-dir-times        omit directories when preserving times\n");
408 +  rprintf(F," -t, --times                 preserve modify times\n");
409 +  rprintf(F," -O, --omit-dir-times        omit directories when preserving modify times\n");
410 +  rprintf(F," -U, --atimes                preserve access (use) times\n");
411    rprintf(F,"     --super                 receiver attempts super-user activities\n");
412    rprintf(F," -S, --sparse                handle sparse files efficiently\n");
413    rprintf(F," -n, --dry-run               show what would have been transferred\n");
414 @@ -424,6 +426,9 @@ static struct poptOption long_options[] 
415    {"times",           't', POPT_ARG_VAL,    &preserve_times, 1, 0, 0 },
416    {"no-times",         0,  POPT_ARG_VAL,    &preserve_times, 0, 0, 0 },
417    {"no-t",             0,  POPT_ARG_VAL,    &preserve_times, 0, 0, 0 },
418 +  {"atimes",          'U', POPT_ARG_VAL,    &preserve_atimes, 1, 0, 0 },
419 +  {"no-atimes",        0,  POPT_ARG_VAL,    &preserve_atimes, 0, 0, 0 },
420 +  {"no-k",             0,  POPT_ARG_VAL,    &preserve_atimes, 0, 0, 0 },
421    {"omit-dir-times",  'O', POPT_ARG_VAL,    &omit_dir_times, 2, 0, 0 },
422    {"modify-window",    0,  POPT_ARG_INT,    &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
423    {"super",            0,  POPT_ARG_VAL,    &am_root, 2, 0, 0 },
424 @@ -1534,6 +1539,8 @@ void server_options(char **args,int *arg
425                 argstr[x++] = 'D';
426         if (preserve_times)
427                 argstr[x++] = 't';
428 +       if (preserve_atimes)
429 +               argstr[x++] = 'U';
430         if (preserve_perms)
431                 argstr[x++] = 'p';
432         else if (preserve_executability && am_sender)
433 --- old/rsync.c
434 +++ new/rsync.c
435 @@ -34,6 +34,7 @@ extern int verbose;
436  extern int dry_run;
437  extern int preserve_perms;
438  extern int preserve_executability;
439 +extern int preserve_atimes;
440  extern int preserve_times;
441  extern int omit_dir_times;
442  extern int am_root;
443 @@ -129,6 +130,7 @@ int set_file_attrs(char *fname, struct f
444         int updated = 0;
445         STRUCT_STAT st2;
446         int change_uid, change_gid;
447 +       time_t atime, mtime;
448         mode_t new_mode = file->mode;
449  
450         if (!st) {
451 @@ -148,18 +150,33 @@ int set_file_attrs(char *fname, struct f
452                 }
453         }
454  
455 +       /* This code must be the first update in the function due to
456 +        * how it uses the "updated" variable. */
457         if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
458                 flags |= ATTRS_SKIP_MTIME;
459 +       if (!preserve_atimes || S_ISDIR(st->st_mode))
460 +               flags |= ATTRS_SKIP_ATIME;
461         if (!(flags & ATTRS_SKIP_MTIME)
462             && cmp_time(st->st_mtime, file->modtime) != 0) {
463 -               int ret = set_modtime(fname, file->modtime, st->st_mode);
464 +               mtime = file->modtime;
465 +               updated = 1;
466 +       } else
467 +               mtime = st->st_mtime;
468 +       if (!(flags & ATTRS_SKIP_ATIME)
469 +           && cmp_time(st->st_atime, file->atime) != 0) {
470 +               atime = file->atime;
471 +               updated = 1;
472 +       } else
473 +               atime = st->st_atime;
474 +       if (updated) {
475 +               int ret = set_times(fname, mtime, atime, st->st_mode);
476                 if (ret < 0) {
477                         rsyserr(FERROR, errno, "failed to set times on %s",
478                                 full_fname(fname));
479                         return 0;
480                 }
481 -               if (ret == 0) /* ret == 1 if symlink could not be set */
482 -                       updated = 1;
483 +               if (ret > 0) /* ret == 1 if symlink could not be set */
484 +                       updated = 0;
485         }
486  
487         change_uid = am_root && preserve_uid && st->st_uid != file->uid;
488 --- old/rsync.h
489 +++ new/rsync.h
490 @@ -54,6 +54,7 @@
491  #define XMIT_HAS_IDEV_DATA (1<<9)
492  #define XMIT_SAME_DEV (1<<10)
493  #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
494 +#define XMIT_SAME_ATIME (1<<12)
495  
496  /* These flags are used in the live flist data. */
497  
498 @@ -120,6 +121,7 @@
499  
500  #define ATTRS_REPORT           (1<<0)
501  #define ATTRS_SKIP_MTIME       (1<<1)
502 +#define ATTRS_SKIP_ATIME       (1<<2)
503  
504  #define FULL_FLUSH     1
505  #define NORMAL_FLUSH   0
506 @@ -530,9 +532,12 @@ struct file_struct {
507         uid_t uid;
508         gid_t gid;
509         mode_t mode;
510 -       uchar flags;    /* this item MUST remain last */
511 +       time_t atime;   /* this MUST be second to last */
512 +       uchar fl4g5;    /* this item MUST remain last */
513  };
514  
515 +#define FFLAGS(f) ((uchar*)(f))[file_struct_len-1]
516 +
517  /*
518   * Start the flist array at FLIST_START entries and grow it
519   * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
520 --- old/rsync.yo
521 +++ new/rsync.yo
522 @@ -327,8 +327,9 @@ to the detailed description below for a 
523       --devices               preserve device files (super-user only)
524       --specials              preserve special files
525   -D                          same as --devices --specials
526 - -t, --times                 preserve times
527 - -O, --omit-dir-times        omit directories when preserving times
528 + -t, --times                 preserve modify times
529 + -O, --omit-dir-times        omit directories when preserving mod-times
530 + -U, --atimes                preserve access (use) times
531       --super                 receiver attempts super-user activities
532   -S, --sparse                handle sparse files efficiently
533   -n, --dry-run               show what would have been transferred
534 @@ -861,6 +862,12 @@ it is preserving modification times (see
535  the directories on the receiving side, it is a good idea to use bf(-O).
536  This option is inferred if you use bf(--backup) without bf(--backup-dir).
537  
538 +dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the
539 +destination files to the same value as the source files.  Note that the
540 +reading of the source file may update the atime of the source files, so
541 +repeated rsync runs with --atimes may be needed if you want to force the
542 +access-time values to be 100% identical on the two systems.
543 +
544  dit(bf(--super)) This tells the receiving side to attempt super-user
545  activities even if the receiving rsync wasn't run by the super-user.  These
546  activities include: preserving users via the bf(--owner) option, preserving
547 @@ -1382,7 +1389,7 @@ with older versions of rsync, but that a
548  verbose messages).
549  
550  The "%i" escape has a cryptic output that is 9 letters long.  The general
551 -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
552 +format is like the string bf(YXcstpogu), where bf(Y) is replaced by the
553  type of update being done, bf(X) is replaced by the file-type, and the
554  other letters represent attributes that may be output if they are being
555  modified.
556 @@ -1422,7 +1429,7 @@ quote(itemization(
557    by the file transfer.
558    it() A bf(t) means the modification time is different and is being updated
559    to the sender's value (requires bf(--times)).  An alternate value of bf(T)
560 -  means that the time will be set to the transfer time, which happens
561 +  means that the modify time will be set to the transfer time, which happens
562    anytime a symlink is transferred, or when a file or device is transferred
563    without bf(--times).
564    it() A bf(p) means the permissions are different and are being updated to
565 @@ -1431,7 +1438,10 @@ quote(itemization(
566    sender's value (requires bf(--owner) and super-user privileges).
567    it() A bf(g) means the group is different and is being updated to the
568    sender's value (requires bf(--group) and the authority to set the group).
569 -  it() The bf(z) slot is reserved for future use.
570 +  it() A bf(u) means the access (use) time is different and is being updated to
571 +  the sender's value (requires bf(--atimes)).  An alternate value of bf(U)
572 +  means that the access time will be set to the transfer time, which happens
573 +  when a symlink or directory is updated.
574  ))
575  
576  One other output is possible:  when deleting files, the "%i" will output
577 --- old/sender.c
578 +++ new/sender.c
579 @@ -41,6 +41,7 @@ extern int do_progress;
580  extern int inplace;
581  extern int batch_fd;
582  extern int write_batch;
583 +extern unsigned int file_struct_len;
584  extern struct stats stats;
585  extern struct file_list *the_file_list;
586  extern char *stdout_format;
587 @@ -373,7 +374,7 @@ void send_files(struct file_list *flist,
588                         rprintf(FINFO, "sender finished %s\n", fname);
589  
590                 /* Flag that we actually sent this entry. */
591 -               file->flags |= FLAG_SENT;
592 +               FFLAGS(file) |= FLAG_SENT;
593         }
594         make_backups = save_make_backups;
595  
596 --- old/testsuite/atimes.test
597 +++ new/testsuite/atimes.test
598 @@ -0,0 +1,19 @@
599 +#! /bin/sh
600 +
601 +# Test rsync copying atimes
602 +
603 +. "$suitedir/rsync.fns"
604 +
605 +set -x
606 +
607 +mkdir "$fromdir"
608 +
609 +touch "$fromdir/foo"
610 +touch -a -t 200102031717.42 "$fromdir/foo"
611 +
612 +TLS_ARGS=--atime
613 +
614 +checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
615 +
616 +# The script would have aborted on error, so getting here means we've won.
617 +exit 0
618 --- old/testsuite/rsync.fns
619 +++ new/testsuite/rsync.fns
620 @@ -66,7 +66,7 @@ printmsg() {
621  }
622  
623  rsync_ls_lR() {
624 -    find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
625 +    find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
626  }
627  
628  check_perms() {
629 @@ -184,6 +184,10 @@ checkit() {
630      # We can just write everything to stdout/stderr, because the
631      # wrapper hides it unless there is a problem.
632  
633 +    if test x$TLS_ARGS = x--atime; then
634 +       ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
635 +    fi
636 +
637      echo "Running: \"$1\""  
638      eval "$1" 
639      status=$?
640 @@ -191,10 +195,13 @@ checkit() {
641         failed="YES";
642      fi
643  
644 +    if test x$TLS_ARGS != x--atime; then
645 +       ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
646 +    fi
647 +
648      echo "-------------"
649      echo "check how the directory listings compare with diff:"
650      echo ""
651 -    ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
652      ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
653      diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
654  
655 --- old/tls.c
656 +++ new/tls.c
657 @@ -34,6 +34,7 @@
658   * change. */
659  
660  #include "rsync.h"
661 +#include "popt.h"
662  
663  #define PROGRAM "tls"
664  
665 @@ -43,6 +44,8 @@ int read_only = 1;
666  int list_only = 0;
667  int preserve_perms = 0;
668  
669 +static int display_atime = 0;
670
671  static void failed(char const *what, char const *where)
672  {
673         fprintf(stderr, PROGRAM ": %s %s: %s\n",
674 @@ -50,12 +53,29 @@ static void failed(char const *what, cha
675         exit(1);
676  }
677  
678 +static void storetime(char *dest, time_t t, size_t destsize)
679 +{
680 +       if (t) {
681 +               struct tm *mt = gmtime(&t);
682 +
683 +               snprintf(dest, destsize,
684 +                       "%04d-%02d-%02d %02d:%02d:%02d ",
685 +                       (int)mt->tm_year + 1900,
686 +                       (int)mt->tm_mon + 1,
687 +                       (int)mt->tm_mday,
688 +                       (int)mt->tm_hour,
689 +                       (int)mt->tm_min,
690 +                       (int)mt->tm_sec);
691 +       } else
692 +               strlcpy(dest, "                    ", destsize);
693 +}
694 +
695  static void list_file(const char *fname)
696  {
697         STRUCT_STAT buf;
698         char permbuf[PERMSTRING_SIZE];
699 -       struct tm *mt;
700 -       char datebuf[50];
701 +       char mtimebuf[50];
702 +       char atimebuf[50];
703         char linkbuf[4096];
704  
705         if (do_lstat(fname, &buf) < 0)
706 @@ -88,19 +108,8 @@ static void list_file(const char *fname)
707  
708         permstring(permbuf, buf.st_mode);
709  
710 -       if (buf.st_mtime) {
711 -               mt = gmtime(&buf.st_mtime);
712 -
713 -               snprintf(datebuf, sizeof datebuf,
714 -                       "%04d-%02d-%02d %02d:%02d:%02d",
715 -                       (int)mt->tm_year + 1900,
716 -                       (int)mt->tm_mon + 1,
717 -                       (int)mt->tm_mday,
718 -                       (int)mt->tm_hour,
719 -                       (int)mt->tm_min,
720 -                       (int)mt->tm_sec);
721 -       } else
722 -               strlcpy(datebuf, "                   ", sizeof datebuf);
723 +       storetime(mtimebuf, buf.st_mtime, sizeof mtimebuf);
724 +       storetime(atimebuf, buf.st_atime, sizeof atimebuf);
725  
726         /* TODO: Perhaps escape special characters in fname? */
727  
728 @@ -111,23 +120,55 @@ static void list_file(const char *fname)
729                     (long)minor(buf.st_rdev));
730         } else /* NB: use double for size since it might not fit in a long. */
731                 printf("%12.0f", (double)buf.st_size);
732 -       printf(" %6ld.%-6ld %6ld %s %s%s\n",
733 +       printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
734                (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
735 -              datebuf, fname, linkbuf);
736 +              mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "",
737 +              fname, linkbuf);
738 +}
739 +
740 +static struct poptOption long_options[] = {
741 +  /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
742 +  {"atime",           'u', POPT_ARG_NONE,   &display_atime, 0,   0, 0},
743 +  {"help",            'h', POPT_ARG_NONE,   0,              'h', 0, 0},
744 +  {0,0,0,0,0,0,0}
745 +};
746 +
747 +static void tls_usage(int ret)
748 +{
749 +       fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
750 +           "Trivial file listing program for portably checking rsync\n");
751 +       exit(ret);
752  }
753  
754  int
755  main(int argc, char *argv[])
756  {
757 -       if (argc < 2) {
758 -               fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
759 -                       "Trivial file listing program for portably checking rsync\n");
760 -               return 1;
761 +       poptContext pc;
762 +       const char **extra_args;
763 +       int opt;
764 +
765 +       pc = poptGetContext(PROGRAM, argc, (const char **)argv,
766 +                           long_options, 0);
767 +       while ((opt = poptGetNextOpt(pc)) != -1) {
768 +               switch (opt) {
769 +               case 'h':
770 +                       tls_usage(0);
771 +               default:
772 +                       fprintf(stderr,
773 +                               "%s: %s\n",
774 +                               poptBadOption(pc, POPT_BADOPTION_NOALIAS),
775 +                               poptStrerror(opt));
776 +                       tls_usage(1);
777 +               }
778         }
779  
780 -       for (argv++; *argv; argv++) {
781 -               list_file(*argv);
782 -       }
783 +       extra_args = poptGetArgs(pc);
784 +       if (*extra_args == NULL)
785 +               tls_usage(1);
786 +
787 +       for (; *extra_args; extra_args++)
788 +               list_file(*extra_args);
789 +       poptFreeContext(pc);
790  
791         return 0;
792  }
793 --- old/util.c
794 +++ new/util.c
795 @@ -121,7 +121,7 @@ NORETURN void overflow_exit(char *str)
796         exit_cleanup(RERR_MALLOC);
797  }
798  
799 -int set_modtime(char *fname, time_t modtime, mode_t mode)
800 +int set_times(char *fname, time_t modtime, time_t atime, mode_t mode)
801  {
802  #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
803         if (S_ISLNK(mode))
804 @@ -129,9 +129,13 @@ int set_modtime(char *fname, time_t modt
805  #endif
806  
807         if (verbose > 2) {
808 -               rprintf(FINFO, "set modtime of %s to (%ld) %s",
809 +               char mtimebuf[200];
810 +
811 +               strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
812 +               rprintf(FINFO,
813 +                       "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
814                         fname, (long)modtime,
815 -                       asctime(localtime(&modtime)));
816 +                       mtimebuf, (long)atime, timestring(atime));
817         }
818  
819         if (dry_run)
820 @@ -140,7 +144,7 @@ int set_modtime(char *fname, time_t modt
821         {
822  #ifdef HAVE_UTIMES
823                 struct timeval t[2];
824 -               t[0].tv_sec = time(NULL);
825 +               t[0].tv_sec = atime;
826                 t[0].tv_usec = 0;
827                 t[1].tv_sec = modtime;
828                 t[1].tv_usec = 0;
829 @@ -151,12 +155,12 @@ int set_modtime(char *fname, time_t modt
830                 return utimes(fname, t);
831  #elif defined HAVE_UTIMBUF
832                 struct utimbuf tbuf;
833 -               tbuf.actime = time(NULL);
834 +               tbuf.actime = atime;
835                 tbuf.modtime = modtime;
836                 return utime(fname,&tbuf);
837  #elif defined HAVE_UTIME
838                 time_t t[2];
839 -               t[0] = time(NULL);
840 +               t[0] = atime;
841                 t[1] = modtime;
842                 return utime(fname,t);
843  #else