Fixed failing hunks.
[rsync/rsync-patches.git] / atimes.diff
... / ...
CommitLineData
1To use this patch, run these commands for a successful build:
2
3 patch -p1 <patches/atimes.diff
4 ./prepare-source
5 ./configure (optional if already run)
6 make
7
8
9--- old/flist.c
10+++ new/flist.c
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)
20 struct file_struct f;
21
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);
26+ else
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;
32 }
33
34@@ -135,16 +142,18 @@ static void list_file_entry(struct file_
35
36 #ifdef SUPPORT_LINKS
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",
40 permbuf,
41 (double)f->length, timestring(f->modtime),
42+ preserve_atimes ? timestring(f->atime) : "",
43 f_name(f, NULL), f->u.link);
44 } else
45 #endif
46 {
47- rprintf(FINFO, "%s %11.0f %s %s\n",
48+ rprintf(FINFO, "%s %11.0f %s %s %s\n",
49 permbuf,
50 (double)f->length, timestring(f->modtime),
51+ preserve_atimes ? timestring(f->atime) : "",
52 f_name(f, NULL));
53 }
54 }
55@@ -302,6 +311,7 @@ static void send_file_entry(struct file_
56 {
57 unsigned short flags;
58 static time_t modtime;
59+ static time_t atime;
60 static mode_t mode;
61 static int64 dev;
62 static dev_t rdev;
63@@ -317,7 +327,7 @@ static void send_file_entry(struct file_
64
65 if (!file) {
66 write_byte(f, 0);
67- modtime = 0, mode = 0;
68+ modtime = 0, atime = 0, mode = 0;
69 dev = 0, rdev = MAKEDEV(0, 0);
70 rdev_major = 0;
71 uid = 0, gid = 0;
72@@ -327,7 +337,7 @@ static void send_file_entry(struct file_
73
74 f_name(file, fname);
75
76- flags = file->flags & XMIT_TOP_DIR;
77+ flags = FFLAGS(file) & XMIT_TOP_DIR;
78
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;
83 else
84 modtime = file->modtime;
85+ if (preserve_atimes && !S_ISDIR(mode)) {
86+ if (file->atime == atime)
87+ flags |= XMIT_SAME_ATIME;
88+ else
89+ atime = file->atime;
90+ }
91
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)) {
101 if (!numeric_ids)
102 add_uid(uid);
103@@ -482,6 +500,7 @@ static struct file_struct *receive_file_
104 unsigned short flags, int f)
105 {
106 static time_t modtime;
107+ static time_t atime;
108 static mode_t mode;
109 static int64 dev;
110 static dev_t rdev;
111@@ -500,7 +519,7 @@ static struct file_struct *receive_file_
112 struct file_struct *file;
113
114 if (!flist) {
115- modtime = 0, mode = 0;
116+ modtime = 0, atime = 0, mode = 0;
117 dev = 0, rdev = MAKEDEV(0, 0);
118 rdev_major = 0;
119 uid = 0, gid = 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);
126
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_
130 file->mode = mode;
131 file->uid = uid;
132 file->gid = gid;
133+ if (preserve_atimes)
134+ file->atime = atime;
135
136 if (dirname_len) {
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;
150 else
151 in_del_hier = 0;
152 }
153@@ -858,12 +881,14 @@ struct file_struct *make_file(char *fnam
154 memset(bp, 0, file_struct_len);
155 bp += file_struct_len;
156
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;
166
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] == '/');
171
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)) {
175 void *save_filters;
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
179 }
180 /* Make sure we don't lose track of a user-specified
181 * top directory. */
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);
187
188 clear_file(flist->files[drop], flist);
189
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));
196 }
197 }
198
199--- old/generator.c
200+++ new/generator.c
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;
216
217@@ -210,7 +212,7 @@ static enum delret delete_dir_contents(c
218 for (j = dirlist->count; j--; ) {
219 struct file_struct *fp = dirlist->files[j];
220
221- if (fp->flags & FLAG_MOUNT_POINT) {
222+ if (FFLAGS(fp) & FLAG_MOUNT_POINT) {
223 if (verbose > 1) {
224 rprintf(FINFO,
225 "mount point, %s, pins parent directory\n",
226@@ -285,7 +287,7 @@ static void delete_in_dir(struct file_li
227 filt_array[cur_depth] = push_local_filters(fbuf, dlen);
228
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)
234 return;
235@@ -299,7 +301,7 @@ static void delete_in_dir(struct file_li
236 struct file_struct *fp = dirlist->files[i];
237 if (!fp->basename)
238 continue;
239- if (fp->flags & FLAG_MOUNT_POINT) {
240+ if (FLAGS(fp) & FLAG_MOUNT_POINT) {
241 if (verbose > 1)
242 rprintf(FINFO, "mount point %s not deleted\n",
243 f_name(fp, NULL));
244@@ -329,11 +331,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];
247
248- if (!(file->flags & FLAG_DEL_HERE))
249+ if (!(FFLAGS(file) & FLAG_DEL_HERE))
250 continue;
251
252 f_name(file, fbuf);
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);
256
257 if (link_stat(fbuf, &st, keep_dirlinks) < 0
258@@ -378,6 +380,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@@ -581,7 +586,7 @@ static int find_fuzzy(struct file_struct
269 uint32 dist;
270
271 if (!S_ISREG(fp->mode) || !fp->length
272- || fp->flags & FLAG_NO_FUZZY)
273+ || FFLAGS(fp) & FLAG_NO_FUZZY)
274 continue;
275
276 name = fp->basename;
277@@ -689,6 +694,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)
280 goto try_a_copy;
281+ if (preserve_atimes)
282+ set_file_attrs(fname, file, stp, 0);
283 if (preserve_hard_links && file->link_u.links) {
284 if (dry_run)
285 file->link_u.links->link_dest_used = j + 1;
286@@ -1040,7 +1047,7 @@ static void recv_generator(char *fname,
287 rsyserr(FERROR, errno,
288 "recv_generator: mkdir %s failed",
289 full_fname(fname));
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) {
294 rprintf(FERROR,
295@@ -1056,7 +1063,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);
302 return;
303 }
304@@ -1360,7 +1367,7 @@ static void recv_generator(char *fname,
305 if (fuzzy_dirlist) {
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;
310 }
311
312 /* open the file */
313@@ -1625,7 +1632,7 @@ void generate_files(int f_out, struct fi
314 continue;
315 if (!need_retouch_dir_times && file->mode & S_IWUSR)
316 continue;
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];
322--- old/hlink.c
323+++ new/hlink.c
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;
330
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");
335
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;
344 } else
345@@ -181,7 +182,7 @@ int hard_link_check(struct file_struct *
346 {
347 #ifdef SUPPORT_HARD_LINKS
348 int head;
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;
352 else
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)
357 return;
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)) {
362 ndx = file->F_NEXT;
363 file = FPTR(ndx);
364 }
365@@ -310,6 +311,6 @@ void hard_link_cluster(struct file_struc
366 send_msg(MSG_SUCCESS, numbuf, 4);
367 }
368 file->F_HLINDEX = FINISHED_LINK;
369- } while (!(file->flags & FLAG_HLINK_EOL));
370+ } while (!(FFLAGS(file) & FLAG_HLINK_EOL));
371 #endif
372 }
373--- old/log.c
374+++ new/log.c
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';
387- n[8] = '.';
388+ n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.'
389+ : S_ISLNK(file->mode) ? 'U' : 'u';
390 n[9] = '\0';
391
392 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
393--- old/options.c
394+++ new/options.c
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;
400 int update_only = 0;
401 int cvs_exclude = 0;
402 int dry_run = 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
426 argstr[x++] = 'D';
427 if (preserve_times)
428 argstr[x++] = 't';
429+ if (preserve_atimes)
430+ argstr[x++] = 'U';
431 if (preserve_perms)
432 argstr[x++] = 'p';
433 else if (preserve_executability && am_sender)
434--- old/rsync.c
435+++ new/rsync.c
436@@ -34,6 +34,7 @@ extern int verbose;
437 extern int dry_run;
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;
443 extern int am_root;
444@@ -129,6 +130,7 @@ int set_file_attrs(char *fname, struct f
445 int updated = 0;
446 STRUCT_STAT st2;
447 int change_uid, change_gid;
448+ time_t atime, mtime;
449 mode_t new_mode = file->mode;
450
451 if (!st) {
452@@ -148,18 +150,33 @@ int set_file_attrs(char *fname, struct f
453 }
454 }
455
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;
466+ updated = 1;
467+ } else
468+ mtime = st->st_mtime;
469+ if (!(flags & ATTRS_SKIP_ATIME)
470+ && cmp_time(st->st_atime, file->atime) != 0) {
471+ atime = file->atime;
472+ updated = 1;
473+ } else
474+ atime = st->st_atime;
475+ if (updated) {
476+ int ret = set_times(fname, mtime, atime, st->st_mode);
477 if (ret < 0) {
478 rsyserr(FERROR, errno, "failed to set times on %s",
479 full_fname(fname));
480 return 0;
481 }
482- if (ret == 0) /* ret == 1 if symlink could not be set */
483- updated = 1;
484+ if (ret > 0) /* ret == 1 if symlink could not be set */
485+ updated = 0;
486 }
487
488 change_uid = am_root && preserve_uid && st->st_uid != file->uid;
489--- old/rsync.h
490+++ new/rsync.h
491@@ -54,6 +54,7 @@
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)
496
497 /* These flags are used in the live flist data. */
498
499@@ -120,6 +121,7 @@
500
501 #define ATTRS_REPORT (1<<0)
502 #define ATTRS_SKIP_MTIME (1<<1)
503+#define ATTRS_SKIP_ATIME (1<<2)
504
505 #define FULL_FLUSH 1
506 #define NORMAL_FLUSH 0
507@@ -531,9 +533,12 @@ struct file_struct {
508 uid_t uid;
509 gid_t gid;
510 mode_t mode;
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 */
514 };
515
516+#define FFLAGS(f) ((uchar*)(f))[file_struct_len-1]
517+
518 /*
519 * Start the flist array at FLIST_START entries and grow it
520 * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
521--- old/rsync.yo
522+++ new/rsync.yo
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).
538
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.
544+
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@@ -1395,7 +1402,7 @@ with older versions of rsync, but that a
549 verbose messages).
550
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
556 modified.
557@@ -1435,7 +1442,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
564 without bf(--times).
565 it() A bf(p) means the permissions are different and are being updated to
566@@ -1444,7 +1451,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.
575 ))
576
577 One other output is possible: when deleting files, the "%i" will output
578--- old/sender.c
579+++ new/sender.c
580@@ -41,6 +41,7 @@ extern int do_progress;
581 extern int inplace;
582 extern int batch_fd;
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);
590
591 /* Flag that we actually sent this entry. */
592- file->flags |= FLAG_SENT;
593+ FFLAGS(file) |= FLAG_SENT;
594 }
595 make_backups = save_make_backups;
596
597--- old/testsuite/atimes.test
598+++ new/testsuite/atimes.test
599@@ -0,0 +1,19 @@
600+#! /bin/sh
601+
602+# Test rsync copying atimes
603+
604+. "$suitedir/rsync.fns"
605+
606+set -x
607+
608+mkdir "$fromdir"
609+
610+touch "$fromdir/foo"
611+touch -a -t 200102031717.42 "$fromdir/foo"
612+
613+TLS_ARGS=--atime
614+
615+checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
616+
617+# The script would have aborted on error, so getting here means we've won.
618+exit 0
619--- old/testsuite/rsync.fns
620+++ new/testsuite/rsync.fns
621@@ -66,7 +66,7 @@ printmsg() {
622 }
623
624 rsync_ls_lR() {
625- find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
626+ find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
627 }
628
629 check_perms() {
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.
633
634+ if test x$TLS_ARGS = x--atime; then
635+ ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
636+ fi
637+
638 echo "Running: \"$1\""
639 eval "$1"
640 status=$?
641@@ -191,10 +195,13 @@ checkit() {
642 failed="YES";
643 fi
644
645+ if test x$TLS_ARGS != x--atime; then
646+ ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
647+ fi
648+
649 echo "-------------"
650 echo "check how the directory listings compare with diff:"
651 echo ""
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
655
656--- old/tls.c
657+++ new/tls.c
658@@ -34,6 +34,7 @@
659 * change. */
660
661 #include "rsync.h"
662+#include "popt.h"
663
664 #define PROGRAM "tls"
665
666@@ -43,6 +44,8 @@ int read_only = 1;
667 int list_only = 0;
668 int preserve_perms = 0;
669
670+static int display_atime = 0;
671+
672 static void failed(char const *what, char const *where)
673 {
674 fprintf(stderr, PROGRAM ": %s %s: %s\n",
675@@ -50,12 +53,29 @@ static void failed(char const *what, cha
676 exit(1);
677 }
678
679+static void storetime(char *dest, time_t t, size_t destsize)
680+{
681+ if (t) {
682+ struct tm *mt = gmtime(&t);
683+
684+ snprintf(dest, destsize,
685+ "%04d-%02d-%02d %02d:%02d:%02d ",
686+ (int)mt->tm_year + 1900,
687+ (int)mt->tm_mon + 1,
688+ (int)mt->tm_mday,
689+ (int)mt->tm_hour,
690+ (int)mt->tm_min,
691+ (int)mt->tm_sec);
692+ } else
693+ strlcpy(dest, " ", destsize);
694+}
695+
696 static void list_file(const char *fname)
697 {
698 STRUCT_STAT buf;
699 char permbuf[PERMSTRING_SIZE];
700- struct tm *mt;
701- char datebuf[50];
702+ char mtimebuf[50];
703+ char atimebuf[50];
704 char linkbuf[4096];
705
706 if (do_lstat(fname, &buf) < 0)
707@@ -88,19 +108,8 @@ static void list_file(const char *fname)
708
709 permstring(permbuf, buf.st_mode);
710
711- if (buf.st_mtime) {
712- mt = gmtime(&buf.st_mtime);
713-
714- snprintf(datebuf, sizeof datebuf,
715- "%04d-%02d-%02d %02d:%02d:%02d",
716- (int)mt->tm_year + 1900,
717- (int)mt->tm_mon + 1,
718- (int)mt->tm_mday,
719- (int)mt->tm_hour,
720- (int)mt->tm_min,
721- (int)mt->tm_sec);
722- } else
723- strlcpy(datebuf, " ", sizeof datebuf);
724+ storetime(mtimebuf, buf.st_mtime, sizeof mtimebuf);
725+ storetime(atimebuf, buf.st_atime, sizeof atimebuf);
726
727 /* TODO: Perhaps escape special characters in fname? */
728
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 : "",
738+ fname, linkbuf);
739+}
740+
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},
745+ {0,0,0,0,0,0,0}
746+};
747+
748+static void tls_usage(int ret)
749+{
750+ fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
751+ "Trivial file listing program for portably checking rsync\n");
752+ exit(ret);
753 }
754
755 int
756 main(int argc, char *argv[])
757 {
758- if (argc < 2) {
759- fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
760- "Trivial file listing program for portably checking rsync\n");
761- return 1;
762- }
763+ poptContext pc;
764+ const char **extra_args;
765+ int opt;
766
767- for (argv++; *argv; argv++) {
768- list_file(*argv);
769+ pc = poptGetContext(PROGRAM, argc, (const char **)argv,
770+ long_options, 0);
771+ while ((opt = poptGetNextOpt(pc)) != -1) {
772+ switch (opt) {
773+ case 'h':
774+ tls_usage(0);
775+ default:
776+ fprintf(stderr,
777+ "%s: %s\n",
778+ poptBadOption(pc, POPT_BADOPTION_NOALIAS),
779+ poptStrerror(opt));
780+ tls_usage(1);
781+ }
782 }
783
784+ extra_args = poptGetArgs(pc);
785+ if (*extra_args == NULL)
786+ tls_usage(1);
787+
788+ for (; *extra_args; extra_args++)
789+ list_file(*extra_args);
790+ poptFreeContext(pc);
791+
792 return 0;
793 }
794--- old/util.c
795+++ new/util.c
796@@ -121,7 +121,7 @@ NORETURN void overflow_exit(char *str)
797 exit_cleanup(RERR_MALLOC);
798 }
799
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)
802 {
803 #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
804 if (S_ISLNK(mode))
805@@ -129,9 +129,13 @@ int set_modtime(char *fname, time_t modt
806 #endif
807
808 if (verbose > 2) {
809- rprintf(FINFO, "set modtime of %s to (%ld) %s",
810+ char mtimebuf[200];
811+
812+ strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
813+ rprintf(FINFO,
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));
818 }
819
820 if (dry_run)
821@@ -140,7 +144,7 @@ int set_modtime(char *fname, time_t modt
822 {
823 #ifdef HAVE_UTIMES
824 struct timeval t[2];
825- t[0].tv_sec = time(NULL);
826+ t[0].tv_sec = atime;
827 t[0].tv_usec = 0;
828 t[1].tv_sec = modtime;
829 t[1].tv_usec = 0;
830@@ -151,12 +155,12 @@ int set_modtime(char *fname, time_t modt
831 return utimes(fname, t);
832 #elif defined HAVE_UTIMBUF
833 struct utimbuf tbuf;
834- tbuf.actime = time(NULL);
835+ tbuf.actime = atime;
836 tbuf.modtime = modtime;
837 return utime(fname,&tbuf);
838 #elif defined HAVE_UTIME
839 time_t t[2];
840- t[0] = time(NULL);
841+ t[0] = atime;
842 t[1] = modtime;
843 return utime(fname,t);
844 #else