- Allow --auto-cmd (-a) additions to be specifed while running.
[rsync/rsync-patches.git] / atimes.diff
CommitLineData
27e96866 1After applying this patch, run these commands for a successful build:
8a529471 2
27e96866
WD
3 ./prepare-source
4 ./configure (optional if already run)
5 make
8a529471
WD
6
7
9a7eef96
WD
8--- old/flist.c
9+++ new/flist.c
4a65fe72
WD
10@@ -51,6 +51,7 @@ extern int preserve_devices;
11 extern int preserve_specials;
81c32ffd
WD
12 extern int preserve_uid;
13 extern int preserve_gid;
14+extern int preserve_atimes;
15 extern int relative_paths;
a5e0f697 16 extern int implied_dirs;
4a65fe72
WD
17 extern int prune_empty_dirs;
18@@ -85,7 +86,13 @@ void init_flist(void)
1cb60481
WD
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)
55602791 24+ file_struct_len = offsetof(struct file_struct, fl4g5);
1cb60481
WD
25+ else
26+ file_struct_len = offsetof(struct file_struct, atime);
55602791
WD
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;
1cb60481
WD
30 checksum_len = protocol_version < 21 ? 2 : MD4_SUM_LENGTH;
31 }
32
4a65fe72 33@@ -141,16 +148,18 @@ static void list_file_entry(struct file_
43581f16 34
09fb8f03 35 #ifdef SUPPORT_LINKS
43581f16
WD
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",
4a65fe72 39 permbuf,
f3e2725a 40 (double)f->length, timestring(f->modtime),
1cb60481 41+ preserve_atimes ? timestring(f->atime) : "",
bd68c3c2 42 f_name(f, NULL), f->u.link);
43581f16
WD
43 } else
44 #endif
896c61d0 45 {
43581f16
WD
46- rprintf(FINFO, "%s %11.0f %s %s\n",
47+ rprintf(FINFO, "%s %11.0f %s %s %s\n",
4a65fe72 48 permbuf,
f3e2725a 49 (double)f->length, timestring(f->modtime),
1cb60481 50+ preserve_atimes ? timestring(f->atime) : "",
bd68c3c2 51 f_name(f, NULL));
896c61d0 52 }
43581f16 53 }
4a65fe72 54@@ -312,6 +321,7 @@ static void send_file_entry(struct file_
43581f16
WD
55 {
56 unsigned short flags;
57 static time_t modtime;
58+ static time_t atime;
59 static mode_t mode;
ba50e96c 60 static int64 dev;
43581f16 61 static dev_t rdev;
4a65fe72 62@@ -327,7 +337,7 @@ static void send_file_entry(struct file_
43581f16
WD
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;
4a65fe72 71@@ -339,7 +349,7 @@ static void send_file_entry(struct file_
1cb60481
WD
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;
4a65fe72 80@@ -375,6 +385,12 @@ static void send_file_entry(struct file_
43581f16
WD
81 flags |= XMIT_SAME_TIME;
82 else
83 modtime = file->modtime;
81c32ffd 84+ if (preserve_atimes && !S_ISDIR(mode)) {
43581f16
WD
85+ if (file->atime == atime)
86+ flags |= XMIT_SAME_ATIME;
87+ else
88+ atime = file->atime;
89+ }
90
09fb8f03 91 #ifdef SUPPORT_HARD_LINKS
43581f16 92 if (file->link_u.idev) {
4a65fe72 93@@ -428,6 +444,8 @@ static void send_file_entry(struct file_
43581f16
WD
94 write_int(f, modtime);
95 if (!(flags & XMIT_SAME_MODE))
96 write_int(f, to_wire_mode(mode));
81c32ffd 97+ if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
43581f16
WD
98+ write_int(f, atime);
99 if (preserve_uid && !(flags & XMIT_SAME_UID)) {
100 if (!numeric_ids)
101 add_uid(uid);
4a65fe72 102@@ -496,6 +514,7 @@ static struct file_struct *receive_file_
09fb8f03 103 unsigned short flags, int f)
43581f16
WD
104 {
105 static time_t modtime;
106+ static time_t atime;
107 static mode_t mode;
ba50e96c 108 static int64 dev;
43581f16 109 static dev_t rdev;
4a65fe72 110@@ -514,7 +533,7 @@ static struct file_struct *receive_file_
43581f16
WD
111 struct file_struct *file;
112
a7219d20 113 if (!flist) {
43581f16
WD
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;
4a65fe72 119@@ -570,6 +589,8 @@ static struct file_struct *receive_file_
43581f16
WD
120 modtime = (time_t)read_int(f);
121 if (!(flags & XMIT_SAME_MODE))
122 mode = from_wire_mode(read_int(f));
81c32ffd 123+ if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME))
43581f16
WD
124+ atime = (time_t)read_int(f);
125
1cb60481
WD
126 if (chmod_modes && !S_ISLNK(mode))
127 mode = tweak_mode(mode, chmod_modes);
4a65fe72 128@@ -625,6 +646,8 @@ static struct file_struct *receive_file_
43581f16 129 file->mode = mode;
8a04c9a7
WD
130 file->uid = uid;
131 file->gid = gid;
1cb60481
WD
132+ if (preserve_atimes)
133+ file->atime = atime;
134
135 if (dirname_len) {
136 file->dirname = lastdir = bp;
4a65fe72 137@@ -650,12 +673,12 @@ static struct file_struct *receive_file_
1cb60481
WD
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 }
4a65fe72 152@@ -871,12 +894,14 @@ struct file_struct *make_file(char *fnam
1cb60481
WD
153 memset(bp, 0, file_struct_len);
154 bp += file_struct_len;
43581f16 155
1cb60481
WD
156- file->flags = flags;
157+ FFLAGS(file) = flags;
43581f16 158 file->modtime = st.st_mtime;
43581f16 159 file->length = st.st_size;
1cb60481 160 file->mode = st.st_mode;
8a04c9a7
WD
161 file->uid = st.st_uid;
162 file->gid = st.st_gid;
1cb60481
WD
163+ if (preserve_atimes)
164+ file->atime = st.st_atime;
165
166 #ifdef SUPPORT_HARD_LINKS
167 if (flist && flist->hlink_pool) {
4a65fe72 168@@ -989,7 +1014,7 @@ static void send_if_directory(int f, str
1cb60481
WD
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] == '/')
4a65fe72 177@@ -1595,8 +1620,9 @@ static void clean_flist(struct file_list
1cb60481 178 }
4a65fe72
WD
179 /* Make sure we don't lose track of a user-specified
180 * top directory. */
1cb60481
WD
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
4a65fe72 187 clear_file(flist->files[drop], flist);
1cb60481 188
4a65fe72 189@@ -1720,7 +1746,7 @@ static void output_flist(struct file_lis
1cb60481
WD
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
9a7eef96
WD
198--- old/generator.c
199+++ new/generator.c
7a56a8f1 200@@ -44,6 +44,7 @@ extern int preserve_perms;
55602791 201 extern int preserve_uid;
81c32ffd
WD
202 extern int preserve_gid;
203 extern int preserve_times;
81c32ffd 204+extern int preserve_atimes;
55602791 205 extern int omit_dir_times;
4a65fe72 206 extern int delete_mode;
81c32ffd 207 extern int delete_before;
7a56a8f1 208@@ -91,6 +92,7 @@ extern dev_t filesystem_dev;
1cb60481
WD
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
7a56a8f1 216@@ -185,7 +187,7 @@ static int delete_item(char *fname, int
1cb60481
WD
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);
7a56a8f1 225@@ -263,7 +265,7 @@ static void delete_in_dir(struct file_li
1cb60481
WD
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;
7a56a8f1 234@@ -275,7 +277,7 @@ static void delete_in_dir(struct file_li
1cb60481
WD
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) {
4a65fe72 242 f_name(fp, delbuf);
7a56a8f1 243@@ -301,11 +303,11 @@ static void do_delete_pass(struct file_l
1cb60481
WD
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
577db5e2 257@@ -349,6 +351,9 @@ void itemize(struct file_struct *file, i
55602791 258 && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
577db5e2 259 || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0))
f20eb450 260 iflags |= ITEM_REPORT_TIME;
55602791
WD
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;
7a56a8f1 264 if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
f20eb450 265 iflags |= ITEM_REPORT_PERMS;
7a56a8f1 266 if (preserve_uid && am_root && file->uid != st->st_uid)
577db5e2 267@@ -550,7 +555,7 @@ static int find_fuzzy(struct file_struct
1cb60481
WD
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
81c32ffd 275 name = fp->basename;
7a56a8f1 276@@ -659,6 +664,8 @@ static int try_dests_reg(struct file_str
8a04c9a7
WD
277 itemizing && verbose > 1,
278 code) < 0)
279 goto try_a_copy;
280+ if (preserve_atimes)
4a65fe72 281+ set_file_attrs(fname, file, stp, 0);
8a04c9a7
WD
282 if (preserve_hard_links && file->link_u.links)
283 hard_link_cluster(file, ndx, itemizing, code);
284 } else if (itemizing)
7a56a8f1 285@@ -894,7 +901,7 @@ static void recv_generator(char *fname,
1cb60481
WD
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 }
7a56a8f1 294@@ -1176,7 +1183,7 @@ static void recv_generator(char *fname,
1cb60481
WD
295 if (fuzzy_basis) {
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 */
9a7eef96
WD
303--- old/hlink.c
304+++ new/hlink.c
1cb60481
WD
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 }
9a7eef96
WD
354--- old/log.c
355+++ new/log.c
577db5e2
WD
356@@ -42,6 +42,7 @@ extern int msg_fd_out;
357 extern int allow_8bit_chars;
81c32ffd
WD
358 extern int protocol_version;
359 extern int preserve_times;
360+extern int preserve_atimes;
f20eb450 361 extern int log_format_has_i;
81c32ffd
WD
362 extern int log_format_has_o_or_i;
363 extern int daemon_log_format_has_o_or_i;
577db5e2 364@@ -605,10 +606,12 @@ static void log_formatted(enum logcode c
55602791 365 n[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's';
81c32ffd 366 n[4] = !(iflags & ITEM_REPORT_TIME) ? '.'
55602791 367 : !preserve_times || S_ISLNK(file->mode) ? 'T' : 't';
81c32ffd
WD
368- n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
369- n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
370- n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
55602791 371- n[8] = '\0';
81c32ffd 372+ n[5] = !(iflags & ITEM_REPORT_ATIME) ? '.'
55602791 373+ : S_ISLNK(file->mode) ? 'U' : 'u';
81c32ffd
WD
374+ n[6] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
375+ n[7] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
376+ n[8] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
55602791 377+ n[9] = '\0';
81c32ffd
WD
378
379 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
380 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
9a7eef96
WD
381--- old/options.c
382+++ new/options.c
4a65fe72 383@@ -52,6 +52,7 @@ int preserve_uid = 0;
43581f16
WD
384 int preserve_gid = 0;
385 int preserve_times = 0;
9a21ad72 386 int omit_dir_times = 0;
81c32ffd 387+int preserve_atimes = 0;
43581f16
WD
388 int update_only = 0;
389 int cvs_exclude = 0;
390 int dry_run = 0;
577db5e2 391@@ -300,8 +301,9 @@ void usage(enum logcode F)
4a65fe72
WD
392 rprintf(F," --devices preserve device files (super-user only)\n");
393 rprintf(F," --specials preserve special files\n");
394 rprintf(F," -D same as --devices --specials\n");
81c32ffd
WD
395- rprintf(F," -t, --times preserve times\n");
396- rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
397+ rprintf(F," -t, --times preserve modify times\n");
398+ rprintf(F," -O, --omit-dir-times omit directories when preserving modify times\n");
55602791 399+ rprintf(F," -U, --atimes preserve access (use) times\n");
4a65fe72 400 rprintf(F," --super receiver attempts super-user activities\n");
43581f16
WD
401 rprintf(F," -S, --sparse handle sparse files efficiently\n");
402 rprintf(F," -n, --dry-run show what would have been transferred\n");
577db5e2 403@@ -414,6 +416,9 @@ static struct poptOption long_options[]
489b0a72
WD
404 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
405 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
406 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
55602791 407+ {"atimes", 'U', POPT_ARG_VAL, &preserve_atimes, 1, 0, 0 },
489b0a72 408+ {"no-atimes", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
58070e2e 409+ {"no-k", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
52f25864 410 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
489b0a72 411 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
4a65fe72 412 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
afcb578c 413@@ -1507,6 +1512,8 @@ void server_options(char **args,int *arg
43581f16
WD
414 argstr[x++] = 'D';
415 if (preserve_times)
416 argstr[x++] = 't';
81c32ffd 417+ if (preserve_atimes)
55602791 418+ argstr[x++] = 'U';
43581f16 419 if (preserve_perms)
4a65fe72
WD
420 argstr[x++] = 'p';
421 else if (preserve_executability && am_sender)
9a7eef96
WD
422--- old/rsync.c
423+++ new/rsync.c
7a56a8f1 424@@ -37,6 +37,7 @@ extern int preserve_perms;
4a65fe72 425 extern int preserve_executability;
43581f16 426 extern int preserve_times;
9a21ad72 427 extern int omit_dir_times;
81c32ffd 428+extern int preserve_atimes;
4a65fe72 429 extern int orig_umask;
43581f16 430 extern int am_root;
a7219d20 431 extern int am_server;
577db5e2 432@@ -125,6 +126,7 @@ int set_file_attrs(char *fname, struct f
9a21ad72
WD
433 int updated = 0;
434 STRUCT_STAT st2;
435 int change_uid, change_gid;
436+ time_t atime, mtime;
437
438 if (!st) {
439 if (dry_run)
577db5e2 440@@ -143,18 +145,33 @@ int set_file_attrs(char *fname, struct f
7a56a8f1 441 }
8a04c9a7 442 }
9a21ad72 443
8a04c9a7
WD
444+ /* This code must be the first update in the function due to
445+ * how it uses the "updated" variable. */
9e355bf1 446 if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
4a65fe72 447 flags |= ATTRS_SKIP_MTIME;
81c32ffd 448+ if (!preserve_atimes || S_ISDIR(st->st_mode))
4a65fe72
WD
449+ flags |= ATTRS_SKIP_ATIME;
450 if (!(flags & ATTRS_SKIP_MTIME)
577db5e2 451 && cmp_time(st->st_mtime, file->modtime) != 0) {
9e355bf1 452- int ret = set_modtime(fname, file->modtime, st->st_mode);
9a21ad72 453+ mtime = file->modtime;
9e355bf1 454+ updated = 1;
9a21ad72
WD
455+ } else
456+ mtime = st->st_mtime;
4a65fe72 457+ if (!(flags & ATTRS_SKIP_ATIME)
81c32ffd
WD
458+ && cmp_time(st->st_atime, file->atime) != 0) {
459+ atime = file->atime;
460+ updated = 1;
461+ } else
462+ atime = st->st_atime;
9e355bf1
WD
463+ if (updated) {
464+ int ret = set_times(fname, mtime, atime, st->st_mode);
465 if (ret < 0) {
466 rsyserr(FERROR, errno, "failed to set times on %s",
467 full_fname(fname));
468 return 0;
469 }
470- if (ret == 0) /* ret == 1 if symlink could not be set */
471- updated = 1;
472+ if (ret > 0) /* ret == 1 if symlink could not be set */
473+ updated = 0;
43581f16
WD
474 }
475
8a04c9a7 476 change_uid = am_root && preserve_uid && st->st_uid != file->uid;
9a7eef96
WD
477--- old/rsync.h
478+++ new/rsync.h
43581f16
WD
479@@ -54,6 +54,7 @@
480 #define XMIT_HAS_IDEV_DATA (1<<9)
481 #define XMIT_SAME_DEV (1<<10)
482 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
483+#define XMIT_SAME_ATIME (1<<12)
484
485 /* These flags are used in the live flist data. */
486
610969d1 487@@ -119,6 +120,7 @@
8a529471 488
4a65fe72
WD
489 #define ATTRS_REPORT (1<<0)
490 #define ATTRS_SKIP_MTIME (1<<1)
491+#define ATTRS_SKIP_ATIME (1<<2)
8a529471
WD
492
493 #define FULL_FLUSH 1
494 #define NORMAL_FLUSH 0
f20eb450
WD
495@@ -135,6 +137,7 @@
496 #define FNAMECMP_FUZZY 0x83
81c32ffd
WD
497
498 /* For use by the itemize_changes code */
499+#define ITEM_REPORT_ATIME (1<<0)
500 #define ITEM_REPORT_CHECKSUM (1<<1)
501 #define ITEM_REPORT_SIZE (1<<2)
502 #define ITEM_REPORT_TIME (1<<3)
8a04c9a7
WD
503@@ -520,9 +523,12 @@ struct file_struct {
504 uid_t uid;
505 gid_t gid;
43581f16 506 mode_t mode;
55602791 507- uchar flags; /* this item MUST remain last */
1cb60481 508+ time_t atime; /* this MUST be second to last */
55602791 509+ uchar fl4g5; /* this item MUST remain last */
1cb60481
WD
510 };
511
512+#define FFLAGS(f) ((uchar*)(f))[file_struct_len-1]
513+
514 /*
515 * Start the flist array at FLIST_START entries and grow it
516 * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
9a7eef96
WD
517--- old/rsync.yo
518+++ new/rsync.yo
4a65fe72
WD
519@@ -323,8 +323,9 @@ to the detailed description below for a
520 --devices preserve device files (super-user only)
521 --specials preserve special files
522 -D same as --devices --specials
81c32ffd 523- -t, --times preserve times
610969d1 524- -O, --omit-dir-times omit directories when preserving times
81c32ffd 525+ -t, --times preserve modify times
610969d1 526+ -O, --omit-dir-times omit directories when preserving mod-times
55602791 527+ -U, --atimes preserve access (use) times
4a65fe72 528 --super receiver attempts super-user activities
43581f16
WD
529 -S, --sparse handle sparse files efficiently
530 -n, --dry-run show what would have been transferred
577db5e2 531@@ -801,6 +802,12 @@ it is preserving modification times (see
a7219d20 532 the directories on the receiving side, it is a good idea to use bf(-O).
333b8af4 533 This option is inferred if you use bf(--backup) without bf(--backup-dir).
7b675ff5 534
55602791
WD
535+dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the
536+destination files to the same value as the source files. Note that the
81c32ffd
WD
537+reading of the source file may update the atime of the source files, so
538+repeated rsync runs with --atimes may be needed if you want to force the
539+access-time values to be 100% identical on the two systems.
7b675ff5 540+
4a65fe72
WD
541 dit(bf(--super)) This tells the receiving side to attempt super-user
542 activities even if the receiving rsync wasn't run by the super-user. These
543 activities include: preserving users via the bf(--owner) option, preserving
577db5e2 544@@ -1308,8 +1315,8 @@ if the receiving rsync is at least versi
4a65fe72
WD
545 with older versions of rsync, but that also turns on the output of other
546 verbose messages).
547
548-The "%i" escape has a cryptic output that is 8 letters long. The general
549-format is like the string bf(YXcstpog), where bf(Y) is replaced by the
550+The "%i" escape has a cryptic output that is 9 letters long. The general
551+format is like the string bf(YXcstupog), where bf(Y) is replaced by the
552 kind of update being done, bf(X) is replaced by the file-type, and the
553 other letters represent attributes that may be output if they are being
554 modified.
577db5e2 555@@ -1349,9 +1356,13 @@ quote(itemize(
81c32ffd
WD
556 by the file transfer.
557 it() A bf(t) means the modification time is different and is being updated
558 to the sender's value (requires bf(--times)). An alternate value of bf(T)
559- means that the time will be set to the transfer time, which happens
560+ means that the modify time will be set to the transfer time, which happens
561 anytime a symlink is transferred, or when a file or device is transferred
562 without bf(--times).
55602791
WD
563+ it() A bf(u) means the access (use) time is different and is being updated to
564+ the sender's value (requires bf(--atimes)). An alternate value of bf(U)
565+ means that the access time will be set to the transfer time, which happens
566+ anytime a symlink is transferred.
81c32ffd
WD
567 it() A bf(p) means the permissions are different and are being updated to
568 the sender's value (requires bf(--perms)).
569 it() An bf(o) means the owner is different and is being updated to the
9a7eef96
WD
570--- old/sender.c
571+++ new/sender.c
1cb60481
WD
572@@ -38,6 +38,7 @@ extern int do_progress;
573 extern int inplace;
574 extern int batch_fd;
575 extern int write_batch;
576+extern unsigned int file_struct_len;
577 extern struct stats stats;
578 extern struct file_list *the_file_list;
579 extern char *log_format;
580@@ -126,7 +127,7 @@ void successful_send(int ndx)
581
582 file = the_file_list->files[ndx];
583 /* The generator might tell us about symlinks we didn't send. */
584- if (!(file->flags & FLAG_SENT) && !S_ISLNK(file->mode))
585+ if (!(FFLAGS(file) & FLAG_SENT) && !S_ISLNK(file->mode))
586 return;
587 if (file->dir.root) {
588 offset = stringjoin(fname, sizeof fname,
589@@ -370,7 +371,7 @@ void send_files(struct file_list *flist,
590 rprintf(FINFO, "sender finished %s\n", fname);
591
592 /* Flag that we actually sent this entry. */
593- file->flags |= FLAG_SENT;
594+ FFLAGS(file) |= FLAG_SENT;
595 }
596 make_backups = save_make_backups;
597
9a7eef96
WD
598--- old/testsuite/atimes.test
599+++ new/testsuite/atimes.test
13bed3dd
WD
600@@ -0,0 +1,19 @@
601+#! /bin/sh
602+
603+# Test rsync copying atimes
604+
605+. "$suitedir/rsync.fns"
606+
607+set -x
608+
609+mkdir "$fromdir"
610+
611+touch "$fromdir/foo"
612+touch -a -t 200102031717.42 "$fromdir/foo"
613+
614+TLS_ARGS=--atime
615+
55602791 616+checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
13bed3dd
WD
617+
618+# The script would have aborted on error, so getting here means we've won.
619+exit 0
9a7eef96
WD
620--- old/testsuite/devices.test
621+++ new/testsuite/devices.test
4a65fe72 622@@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc
55602791
WD
623 $RSYNC -ai "$fromdir/block" "$todir/block2" \
624 | tee "$outfile"
625 cat <<EOT >"$chkfile"
626-cD++++++ block
627+cD+++++++ block
628 EOT
629 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
630
631 $RSYNC -ai "$fromdir/block2" "$todir/block" \
632 | tee "$outfile"
633 cat <<EOT >"$chkfile"
634-cD++++++ block2
635+cD+++++++ block2
636 EOT
637 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
638
4a65fe72 639@@ -58,7 +58,7 @@ sleep 1
55602791
WD
640 $RSYNC -Di "$fromdir/block3" "$todir/block" \
641 | tee "$outfile"
642 cat <<EOT >"$chkfile"
643-cD..T... block3
644+cD..T.... block3
645 EOT
646 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
647
4a65fe72 648@@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \
55602791
WD
649 | tee "$outfile"
650 filter_outfile
651 cat <<EOT >"$chkfile"
652-.d..t... ./
653-cD..t... block
654-cD...... block2
655-cD++++++ block3
656-hD++++++ block2.5 => block3
657-cD++++++ char
658-cD++++++ char2
659-cD++++++ char3
4a65fe72 660-cS++++++ fifo
55602791
WD
661+.d..t.... ./
662+cD..t.... block
663+cD....... block2
664+cD+++++++ block3
665+hD+++++++ block2.5 => block3
666+cD+++++++ char
667+cD+++++++ char2
668+cD+++++++ char3
4a65fe72 669+cS+++++++ fifo
55602791
WD
670 EOT
671 if test ! -b "$fromdir/block2.5"; then
672 sed -e '/block2\.5/d' \
9a7eef96
WD
673--- old/testsuite/itemize.test
674+++ new/testsuite/itemize.test
7a56a8f1 675@@ -29,14 +29,14 @@ ln "$fromdir/foo/config1" "$fromdir/foo/
81c32ffd
WD
676 $RSYNC -iplr "$fromdir/" "$todir/" \
677 | tee "$outfile"
678 cat <<EOT >"$chkfile"
55602791
WD
679-cd++++++ bar/
680-cd++++++ bar/baz/
681->f++++++ bar/baz/rsync
682-cd++++++ foo/
683->f++++++ foo/config1
684->f++++++ foo/config2
685->f++++++ foo/extra
686-cL++++++ foo/sym -> ../bar/baz/rsync
687+cd+++++++ bar/
688+cd+++++++ bar/baz/
689+>f+++++++ bar/baz/rsync
690+cd+++++++ foo/
691+>f+++++++ foo/config1
692+>f+++++++ foo/config2
693+>f+++++++ foo/extra
694+cL+++++++ foo/sym -> ../bar/baz/rsync
81c32ffd
WD
695 EOT
696 diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed"
697
7a56a8f1 698@@ -48,10 +48,10 @@ chmod 601 "$fromdir/foo/config2"
81c32ffd
WD
699 $RSYNC -iplrH "$fromdir/" "$todir/" \
700 | tee "$outfile"
701 cat <<EOT >"$chkfile"
55602791
WD
702->f..T... bar/baz/rsync
703->f..T... foo/config1
704->f.sTp.. foo/config2
705-hf..T... foo/extra => foo/config1
706+>f..T.... bar/baz/rsync
707+>f..T.... foo/config1
708+>f.sT.p.. foo/config2
709+hf..T.... foo/extra => foo/config1
81c32ffd
WD
710 EOT
711 diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed"
712
7a56a8f1 713@@ -68,11 +68,11 @@ chmod 777 "$todir/bar/baz/rsync"
81c32ffd
WD
714 $RSYNC -iplrtc "$fromdir/" "$todir/" \
715 | tee "$outfile"
716 cat <<EOT >"$chkfile"
55602791
WD
717-.f..tp.. bar/baz/rsync
718-.d..t... foo/
719-.f..t... foo/config1
720->fcstp.. foo/config2
721-cL..T... foo/sym -> ../bar/baz/rsync
722+.f..t.p.. bar/baz/rsync
723+.d..t.... foo/
724+.f..t.... foo/config1
725+>fcst.p.. foo/config2
726+cL..T.... foo/sym -> ../bar/baz/rsync
81c32ffd
WD
727 EOT
728 diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed"
729
7a56a8f1 730@@ -97,15 +97,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \
81c32ffd
WD
731 | tee "$outfile"
732 filter_outfile
733 cat <<EOT >"$chkfile"
55602791
WD
734-.d ./
735-.d bar/
736-.d bar/baz/
737-.f...p.. bar/baz/rsync
738-.d foo/
739-.f foo/config1
740->f..t... foo/config2
741-hf foo/extra
742-.L foo/sym -> ../bar/baz/rsync
743+.d ./
744+.d bar/
745+.d bar/baz/
746+.f....p.. bar/baz/rsync
747+.d foo/
748+.f foo/config1
749+>f..t.... foo/config2
750+hf foo/extra
751+.L foo/sym -> ../bar/baz/rsync
81c32ffd
WD
752 EOT
753 diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed"
754
7a56a8f1 755@@ -124,8 +124,8 @@ touch "$todir/foo/config2"
81c32ffd
WD
756 $RSYNC -iplrtH "$fromdir/" "$todir/" \
757 | tee "$outfile"
758 cat <<EOT >"$chkfile"
55602791
WD
759-.f...p.. foo/config1
760->f..t... foo/config2
761+.f....p.. foo/config1
762+>f..t.... foo/config2
81c32ffd
WD
763 EOT
764 diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed"
765
7a56a8f1 766@@ -134,15 +134,15 @@ $RSYNC -ivvplrtH --copy-dest="$lddir" "$
81c32ffd
WD
767 | tee "$outfile"
768 filter_outfile
769 cat <<EOT >"$chkfile"
55602791
WD
770-.d..t... ./
771-cd++++++ bar/
772-cd++++++ bar/baz/
773-cf bar/baz/rsync
774-cd++++++ foo/
775-cf foo/config1
776-cf foo/config2
777-hf foo/extra => foo/config1
778-cL..T... foo/sym -> ../bar/baz/rsync
779+.d..t.... ./
780+cd+++++++ bar/
781+cd+++++++ bar/baz/
782+cf bar/baz/rsync
783+cd+++++++ foo/
784+cf foo/config1
785+cf foo/config2
786+hf foo/extra => foo/config1
787+cL..T.... foo/sym -> ../bar/baz/rsync
81c32ffd
WD
788 EOT
789 diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed"
790
7a56a8f1 791@@ -150,11 +150,11 @@ rm -rf "$todir"
f20eb450 792 $RSYNC -iplrtH --copy-dest="$lddir" "$fromdir/" "$todir/" \
81c32ffd
WD
793 | tee "$outfile"
794 cat <<EOT >"$chkfile"
55602791
WD
795-.d..t... ./
796-cd++++++ bar/
797-cd++++++ bar/baz/
798-cd++++++ foo/
799-hf foo/extra => foo/config1
800+.d..t.... ./
801+cd+++++++ bar/
802+cd+++++++ bar/baz/
803+cd+++++++ foo/
804+hf foo/extra => foo/config1
81c32ffd
WD
805 EOT
806 diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed"
807
7a56a8f1 808@@ -181,15 +181,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$
f20eb450
WD
809 | tee "$outfile"
810 filter_outfile
811 cat <<EOT >"$chkfile"
55602791
WD
812-.d..t... ./
813-cd++++++ bar/
814-cd++++++ bar/baz/
815-hf bar/baz/rsync
816-cd++++++ foo/
817-hf foo/config1
818-hf foo/config2
819-hf foo/extra => foo/config1
820-hL foo/sym -> ../bar/baz/rsync
821+.d..t.... ./
822+cd+++++++ bar/
823+cd+++++++ bar/baz/
824+hf bar/baz/rsync
825+cd+++++++ foo/
826+hf foo/config1
827+hf foo/config2
828+hf foo/extra => foo/config1
829+hL foo/sym -> ../bar/baz/rsync
f20eb450
WD
830 EOT
831 diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed"
832
7a56a8f1 833@@ -197,10 +197,10 @@ rm -rf "$todir"
f20eb450
WD
834 $RSYNC -iplrtH --link-dest="$lddir" "$fromdir/" "$todir/" \
835 | tee "$outfile"
836 cat <<EOT >"$chkfile"
55602791
WD
837-.d..t... ./
838-cd++++++ bar/
839-cd++++++ bar/baz/
840-cd++++++ foo/
841+.d..t.... ./
842+cd+++++++ bar/
843+cd+++++++ bar/baz/
844+cd+++++++ foo/
f20eb450
WD
845 EOT
846 diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed"
847
7a56a8f1 848@@ -228,14 +228,14 @@ filter_outfile
f20eb450
WD
849 # TODO fix really-old problem when combining -H with --compare-dest:
850 # missing output for foo/extra hard-link (and it might not be updated)!
851 cat <<EOT >"$chkfile"
55602791
WD
852-.d..t... ./
853-cd++++++ bar/
854-cd++++++ bar/baz/
855-.f bar/baz/rsync
856-cd++++++ foo/
857-.f foo/config1
858-.f foo/config2
859-.L foo/sym -> ../bar/baz/rsync
860+.d..t.... ./
861+cd+++++++ bar/
862+cd+++++++ bar/baz/
863+.f bar/baz/rsync
864+cd+++++++ foo/
865+.f foo/config1
866+.f foo/config2
867+.L foo/sym -> ../bar/baz/rsync
f20eb450
WD
868 EOT
869 diff $diffopt "$chkfile" "$outfile" || test_fail "test 14 failed"
870
7a56a8f1 871@@ -243,10 +243,10 @@ rm -rf "$todir"
f20eb450
WD
872 $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \
873 | tee "$outfile"
874 cat <<EOT >"$chkfile"
55602791
WD
875-.d..t... ./
876-cd++++++ bar/
877-cd++++++ bar/baz/
878-cd++++++ foo/
879+.d..t.... ./
880+cd+++++++ bar/
881+cd+++++++ bar/baz/
882+cd+++++++ foo/
f20eb450
WD
883 EOT
884 diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed"
885
9a7eef96
WD
886--- old/testsuite/rsync.fns
887+++ new/testsuite/rsync.fns
7a56a8f1
WD
888@@ -66,7 +66,7 @@ printmsg() {
889 }
13bed3dd
WD
890
891 rsync_ls_lR() {
b78a6aba
WD
892- find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
893+ find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
13bed3dd
WD
894 }
895
7a56a8f1
WD
896 check_perms() {
897@@ -184,6 +184,10 @@ checkit() {
13bed3dd
WD
898 # We can just write everything to stdout/stderr, because the
899 # wrapper hides it unless there is a problem.
900
81c32ffd
WD
901+ if test x$TLS_ARGS = x--atime; then
902+ ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
903+ fi
13bed3dd
WD
904+
905 echo "Running: \"$1\""
906 eval "$1"
907 status=$?
7a56a8f1 908@@ -191,10 +195,13 @@ checkit() {
81c32ffd
WD
909 failed="YES";
910 fi
911
912+ if test x$TLS_ARGS != x--atime; then
913+ ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
914+ fi
915+
13bed3dd 916 echo "-------------"
b78a6aba
WD
917 echo "check how the directory listings compare with diff:"
918 echo ""
13bed3dd 919- ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
b78a6aba
WD
920 ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
921 diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
4da25dad 922
9a7eef96
WD
923--- old/tls.c
924+++ new/tls.c
43581f16
WD
925@@ -39,6 +39,7 @@
926
927
928 #include "rsync.h"
929+#include "popt.h"
930
931 #define PROGRAM "tls"
932
933@@ -48,6 +49,7 @@ int read_only = 1;
934 int list_only = 0;
935 int preserve_perms = 0;
936
937+static int display_atime = 0;
938
fe6407b5
WD
939 static void failed(char const *what, char const *where)
940 {
941@@ -56,14 +58,29 @@ static void failed(char const *what, cha
942 exit(1);
43581f16
WD
943 }
944
945+static void storetime(char *dest, time_t t)
946+{
947+ if (t) {
948+ struct tm *mt = gmtime(&t);
949
950+ sprintf(dest, "%04d-%02d-%02d %02d:%02d:%02d ",
9d95bd65
WD
951+ (int)mt->tm_year + 1900,
952+ (int)mt->tm_mon + 1,
953+ (int)mt->tm_mday,
954+ (int)mt->tm_hour,
955+ (int)mt->tm_min,
956+ (int)mt->tm_sec);
43581f16
WD
957+ } else {
958+ strcpy(dest, " ");
959+ }
960+}
961
fe6407b5 962 static void list_file(const char *fname)
43581f16
WD
963 {
964 STRUCT_STAT buf;
965 char permbuf[PERMSTRING_SIZE];
966- struct tm *mt;
967- char datebuf[50];
968+ char mtimebuf[50];
969+ char atimebuf[50];
970 char linkbuf[4096];
971
ba50e96c
WD
972 if (do_lstat(fname, &buf) < 0)
973@@ -96,19 +113,8 @@ static void list_file(const char *fname)
43581f16
WD
974
975 permstring(permbuf, buf.st_mode);
976
977- if (buf.st_mtime) {
978- mt = gmtime(&buf.st_mtime);
979-
980- sprintf(datebuf, "%04d-%02d-%02d %02d:%02d:%02d",
9d95bd65
WD
981- (int)mt->tm_year + 1900,
982- (int)mt->tm_mon + 1,
983- (int)mt->tm_mday,
984- (int)mt->tm_hour,
985- (int)mt->tm_min,
986- (int)mt->tm_sec);
43581f16
WD
987- } else {
988- strcpy(datebuf, " ");
989- }
990+ storetime(mtimebuf, buf.st_mtime);
991+ storetime(atimebuf, buf.st_atime);
992
993 /* TODO: Perhaps escape special characters in fname? */
994
ba50e96c 995@@ -119,24 +125,55 @@ static void list_file(const char *fname)
43581f16
WD
996 (long)minor(buf.st_rdev));
997 } else /* NB: use double for size since it might not fit in a long. */
998 printf("%12.0f", (double)buf.st_size);
999- printf(" %6ld.%-6ld %6ld %s %s%s\n",
1000+ printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
1001 (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
1002- datebuf, fname, linkbuf);
c0be1af2 1003+ mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "",
43581f16
WD
1004+ fname, linkbuf);
1005 }
1006
1007+static struct poptOption long_options[] = {
1008+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
1009+ {"atime", 'u', POPT_ARG_NONE, &display_atime, 0, 0, 0},
1010+ {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
1011+ {0,0,0,0,0,0,0}
1012+};
1013+
1014+static void tls_usage(int ret)
1015+{
1016+ fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
1017+ "Trivial file listing program for portably checking rsync\n");
1018+ exit(ret);
1019+}
1020
1021 int
1022 main(int argc, char *argv[])
1023 {
1024- if (argc < 2) {
fe6407b5
WD
1025- fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
1026- "Trivial file listing program for portably checking rsync\n");
43581f16
WD
1027- return 1;
1028+ poptContext pc;
1029+ const char **extra_args;
1030+ int opt;
1031+
1032+ pc = poptGetContext(PROGRAM, argc, (const char **)argv,
1033+ long_options, 0);
1034+ while ((opt = poptGetNextOpt(pc)) != -1) {
1035+ switch (opt) {
1036+ case 'h':
1037+ tls_usage(0);
1038+ default:
1039+ fprintf(stderr,
1040+ "%s: %s\n",
1041+ poptBadOption(pc, POPT_BADOPTION_NOALIAS),
1042+ poptStrerror(opt));
1043+ tls_usage(1);
1044+ }
1045 }
1046
1047- for (argv++; *argv; argv++) {
fe6407b5 1048- list_file(*argv);
43581f16
WD
1049- }
1050+ extra_args = poptGetArgs(pc);
1051+ if (*extra_args == NULL)
1052+ tls_usage(1);
1053+
1054+ for (; *extra_args; extra_args++)
1055+ list_file(*extra_args);
1056+ poptFreeContext(pc);
1057
1058 return 0;
1059 }
9a7eef96
WD
1060--- old/util.c
1061+++ new/util.c
577db5e2
WD
1062@@ -125,7 +125,7 @@ void overflow_exit(char *str)
1063 exit_cleanup(RERR_MALLOC);
1064 }
43581f16 1065
9e355bf1
WD
1066-int set_modtime(char *fname, time_t modtime, mode_t mode)
1067+int set_times(char *fname, time_t modtime, time_t atime, mode_t mode)
43581f16 1068 {
9e355bf1
WD
1069 #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
1070 if (S_ISLNK(mode))
577db5e2 1071@@ -133,9 +133,13 @@ int set_modtime(char *fname, time_t modt
9e355bf1
WD
1072 #endif
1073
43581f16
WD
1074 if (verbose > 2) {
1075- rprintf(FINFO, "set modtime of %s to (%ld) %s",
1076+ char mtimebuf[200];
43581f16 1077+
125d7fca 1078+ strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
43581f16
WD
1079+ rprintf(FINFO,
1080+ "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
93ca4d27 1081 fname, (long)modtime,
43581f16 1082- asctime(localtime(&modtime)));
9e355bf1 1083+ mtimebuf, (long)atime, timestring(atime));
43581f16
WD
1084 }
1085
ba50e96c 1086 if (dry_run)
577db5e2 1087@@ -144,7 +148,7 @@ int set_modtime(char *fname, time_t modt
43581f16 1088 {
9e355bf1
WD
1089 #ifdef HAVE_UTIMES
1090 struct timeval t[2];
1091- t[0].tv_sec = time(NULL);
1092+ t[0].tv_sec = atime;
1093 t[0].tv_usec = 0;
1094 t[1].tv_sec = modtime;
1095 t[1].tv_usec = 0;
577db5e2 1096@@ -155,12 +159,12 @@ int set_modtime(char *fname, time_t modt
9e355bf1
WD
1097 return utimes(fname, t);
1098 #elif defined HAVE_UTIMBUF
43581f16
WD
1099 struct utimbuf tbuf;
1100- tbuf.actime = time(NULL);
1101+ tbuf.actime = atime;
1102 tbuf.modtime = modtime;
1103 return utime(fname,&tbuf);
09fb8f03 1104 #elif defined HAVE_UTIME
43581f16
WD
1105 time_t t[2];
1106- t[0] = time(NULL);
1107+ t[0] = atime;
1108 t[1] = modtime;
1109 return utime(fname,t);
1110 #else