Fixed a bug in rsync_acl_extended_parts_equal() where it could
[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
b0441abd 10@@ -50,6 +50,7 @@ extern int preserve_devices;
4a65fe72 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 17 extern int prune_empty_dirs;
b0441abd 18@@ -84,7 +85,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
b0441abd 33@@ -140,16 +147,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 }
b0441abd 54@@ -311,6 +320,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;
b0441abd 62@@ -326,7 +336,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;
b0441abd 71@@ -338,7 +348,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;
b0441abd 80@@ -374,6 +384,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) {
b0441abd 93@@ -427,6 +443,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);
b0441abd 102@@ -495,6 +513,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;
b0441abd 110@@ -513,7 +532,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;
b0441abd 119@@ -569,6 +588,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);
b0441abd 128@@ -624,6 +645,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;
b0441abd 137@@ -649,12 +672,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 }
b0441abd 152@@ -870,12 +893,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) {
b0441abd 168@@ -988,7 +1013,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] == '/')
b0441abd 177@@ -1594,8 +1619,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
b0441abd 189@@ -1719,7 +1745,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
b0441abd 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;
b0441abd 208@@ -90,6 +91,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
b0441abd 216@@ -184,7 +186,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);
b0441abd 225@@ -262,7 +264,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;
b0441abd 234@@ -274,7 +276,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);
b0441abd 243@@ -300,11 +302,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
b0441abd 257@@ -348,6 +350,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)
b0441abd 267@@ -549,7 +554,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;
b0441abd 276@@ -658,6 +663,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)
d9a67109 285@@ -906,7 +913,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 }
d9a67109
WD
294@@ -1188,7 +1195,7 @@ static void recv_generator(char *fname,
295 if (fuzzy_dirlist) {
1cb60481
WD
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
b0441abd 305@@ -25,6 +25,7 @@ extern int link_dest;
1cb60481
WD
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
b0441abd 313@@ -85,10 +86,10 @@ static void link_idev_data(void)
1cb60481
WD
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;
b0441abd 326@@ -174,7 +175,7 @@ int hard_link_check(struct file_struct *
1cb60481
WD
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];
b0441abd 335@@ -269,8 +270,8 @@ void hard_link_cluster(struct file_struc
1cb60481
WD
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 }
b0441abd 346@@ -285,6 +286,6 @@ void hard_link_cluster(struct file_struc
1cb60481
WD
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;
ccc3a12c
WD
364@@ -608,7 +609,8 @@ static void log_formatted(enum logcode c
365 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
366 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
367 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
368- n[8] = '.';
369+ n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.'
55602791 370+ : S_ISLNK(file->mode) ? 'U' : 'u';
ccc3a12c 371 n[9] = '\0';
81c32ffd
WD
372
373 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
9a7eef96
WD
374--- old/options.c
375+++ new/options.c
b0441abd 376@@ -53,6 +53,7 @@ int preserve_uid = 0;
43581f16
WD
377 int preserve_gid = 0;
378 int preserve_times = 0;
9a21ad72 379 int omit_dir_times = 0;
81c32ffd 380+int preserve_atimes = 0;
43581f16
WD
381 int update_only = 0;
382 int cvs_exclude = 0;
383 int dry_run = 0;
b0441abd 384@@ -301,8 +302,9 @@ void usage(enum logcode F)
4a65fe72
WD
385 rprintf(F," --devices preserve device files (super-user only)\n");
386 rprintf(F," --specials preserve special files\n");
387 rprintf(F," -D same as --devices --specials\n");
81c32ffd
WD
388- rprintf(F," -t, --times preserve times\n");
389- rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
390+ rprintf(F," -t, --times preserve modify times\n");
391+ rprintf(F," -O, --omit-dir-times omit directories when preserving modify times\n");
55602791 392+ rprintf(F," -U, --atimes preserve access (use) times\n");
4a65fe72 393 rprintf(F," --super receiver attempts super-user activities\n");
43581f16
WD
394 rprintf(F," -S, --sparse handle sparse files efficiently\n");
395 rprintf(F," -n, --dry-run show what would have been transferred\n");
b0441abd 396@@ -413,6 +415,9 @@ static struct poptOption long_options[]
489b0a72
WD
397 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
398 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
399 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
55602791 400+ {"atimes", 'U', POPT_ARG_VAL, &preserve_atimes, 1, 0, 0 },
489b0a72 401+ {"no-atimes", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
58070e2e 402+ {"no-k", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
52f25864 403 {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 },
489b0a72 404 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
4a65fe72 405 {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
b0441abd 406@@ -1519,6 +1524,8 @@ void server_options(char **args,int *arg
43581f16
WD
407 argstr[x++] = 'D';
408 if (preserve_times)
409 argstr[x++] = 't';
81c32ffd 410+ if (preserve_atimes)
55602791 411+ argstr[x++] = 'U';
43581f16 412 if (preserve_perms)
4a65fe72
WD
413 argstr[x++] = 'p';
414 else if (preserve_executability && am_sender)
9a7eef96
WD
415--- old/rsync.c
416+++ new/rsync.c
d9a67109
WD
417@@ -35,6 +35,7 @@ extern int dry_run;
418 extern int daemon_log_format_has_i;
419 extern int preserve_perms;
4a65fe72 420 extern int preserve_executability;
d9a67109 421+extern int preserve_atimes;
43581f16 422 extern int preserve_times;
9a21ad72 423 extern int omit_dir_times;
43581f16 424 extern int am_root;
d9a67109 425@@ -128,6 +129,7 @@ int set_file_attrs(char *fname, struct f
9a21ad72
WD
426 int updated = 0;
427 STRUCT_STAT st2;
428 int change_uid, change_gid;
429+ time_t atime, mtime;
430
431 if (!st) {
432 if (dry_run)
d9a67109 433@@ -146,18 +148,33 @@ int set_file_attrs(char *fname, struct f
7a56a8f1 434 }
8a04c9a7 435 }
9a21ad72 436
8a04c9a7
WD
437+ /* This code must be the first update in the function due to
438+ * how it uses the "updated" variable. */
9e355bf1 439 if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times))
4a65fe72 440 flags |= ATTRS_SKIP_MTIME;
81c32ffd 441+ if (!preserve_atimes || S_ISDIR(st->st_mode))
4a65fe72
WD
442+ flags |= ATTRS_SKIP_ATIME;
443 if (!(flags & ATTRS_SKIP_MTIME)
577db5e2 444 && cmp_time(st->st_mtime, file->modtime) != 0) {
9e355bf1 445- int ret = set_modtime(fname, file->modtime, st->st_mode);
9a21ad72 446+ mtime = file->modtime;
9e355bf1 447+ updated = 1;
9a21ad72
WD
448+ } else
449+ mtime = st->st_mtime;
4a65fe72 450+ if (!(flags & ATTRS_SKIP_ATIME)
81c32ffd
WD
451+ && cmp_time(st->st_atime, file->atime) != 0) {
452+ atime = file->atime;
453+ updated = 1;
454+ } else
455+ atime = st->st_atime;
9e355bf1
WD
456+ if (updated) {
457+ int ret = set_times(fname, mtime, atime, st->st_mode);
458 if (ret < 0) {
459 rsyserr(FERROR, errno, "failed to set times on %s",
460 full_fname(fname));
461 return 0;
462 }
463- if (ret == 0) /* ret == 1 if symlink could not be set */
464- updated = 1;
465+ if (ret > 0) /* ret == 1 if symlink could not be set */
466+ updated = 0;
43581f16
WD
467 }
468
8a04c9a7 469 change_uid = am_root && preserve_uid && st->st_uid != file->uid;
9a7eef96
WD
470--- old/rsync.h
471+++ new/rsync.h
43581f16
WD
472@@ -54,6 +54,7 @@
473 #define XMIT_HAS_IDEV_DATA (1<<9)
474 #define XMIT_SAME_DEV (1<<10)
475 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
476+#define XMIT_SAME_ATIME (1<<12)
477
478 /* These flags are used in the live flist data. */
479
610969d1 480@@ -119,6 +120,7 @@
8a529471 481
4a65fe72
WD
482 #define ATTRS_REPORT (1<<0)
483 #define ATTRS_SKIP_MTIME (1<<1)
484+#define ATTRS_SKIP_ATIME (1<<2)
8a529471
WD
485
486 #define FULL_FLUSH 1
487 #define NORMAL_FLUSH 0
b0441abd 488@@ -522,9 +524,12 @@ struct file_struct {
8a04c9a7
WD
489 uid_t uid;
490 gid_t gid;
43581f16 491 mode_t mode;
55602791 492- uchar flags; /* this item MUST remain last */
1cb60481 493+ time_t atime; /* this MUST be second to last */
55602791 494+ uchar fl4g5; /* this item MUST remain last */
1cb60481
WD
495 };
496
497+#define FFLAGS(f) ((uchar*)(f))[file_struct_len-1]
498+
499 /*
500 * Start the flist array at FLIST_START entries and grow it
501 * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
9a7eef96
WD
502--- old/rsync.yo
503+++ new/rsync.yo
b0441abd 504@@ -327,8 +327,9 @@ to the detailed description below for a
4a65fe72
WD
505 --devices preserve device files (super-user only)
506 --specials preserve special files
507 -D same as --devices --specials
81c32ffd 508- -t, --times preserve times
610969d1 509- -O, --omit-dir-times omit directories when preserving times
81c32ffd 510+ -t, --times preserve modify times
610969d1 511+ -O, --omit-dir-times omit directories when preserving mod-times
55602791 512+ -U, --atimes preserve access (use) times
4a65fe72 513 --super receiver attempts super-user activities
43581f16
WD
514 -S, --sparse handle sparse files efficiently
515 -n, --dry-run show what would have been transferred
b0441abd 516@@ -851,6 +852,12 @@ it is preserving modification times (see
a7219d20 517 the directories on the receiving side, it is a good idea to use bf(-O).
333b8af4 518 This option is inferred if you use bf(--backup) without bf(--backup-dir).
7b675ff5 519
55602791
WD
520+dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the
521+destination files to the same value as the source files. Note that the
81c32ffd
WD
522+reading of the source file may update the atime of the source files, so
523+repeated rsync runs with --atimes may be needed if you want to force the
524+access-time values to be 100% identical on the two systems.
7b675ff5 525+
4a65fe72
WD
526 dit(bf(--super)) This tells the receiving side to attempt super-user
527 activities even if the receiving rsync wasn't run by the super-user. These
528 activities include: preserving users via the bf(--owner) option, preserving
b0441abd 529@@ -1366,7 +1373,7 @@ with older versions of rsync, but that a
4a65fe72
WD
530 verbose messages).
531
ccc3a12c
WD
532 The "%i" escape has a cryptic output that is 9 letters long. The general
533-format is like the string bf(YXcstpogz), where bf(Y) is replaced by the
534+format is like the string bf(YXcstpogu), where bf(Y) is replaced by the
535 type of update being done, bf(X) is replaced by the file-type, and the
4a65fe72
WD
536 other letters represent attributes that may be output if they are being
537 modified.
b0441abd 538@@ -1406,7 +1413,7 @@ quote(itemize(
81c32ffd
WD
539 by the file transfer.
540 it() A bf(t) means the modification time is different and is being updated
541 to the sender's value (requires bf(--times)). An alternate value of bf(T)
542- means that the time will be set to the transfer time, which happens
543+ means that the modify time will be set to the transfer time, which happens
544 anytime a symlink is transferred, or when a file or device is transferred
545 without bf(--times).
ccc3a12c 546 it() A bf(p) means the permissions are different and are being updated to
b0441abd 547@@ -1415,7 +1422,10 @@ quote(itemize(
ccc3a12c
WD
548 sender's value (requires bf(--owner) and super-user privileges).
549 it() A bf(g) means the group is different and is being updated to the
550 sender's value (requires bf(--group) and the authority to set the group).
551- it() The bf(z) slot is reserved for future use.
55602791
WD
552+ it() A bf(u) means the access (use) time is different and is being updated to
553+ the sender's value (requires bf(--atimes)). An alternate value of bf(U)
554+ means that the access time will be set to the transfer time, which happens
ccc3a12c
WD
555+ when a symlink or directory is updated.
556 ))
557
558 One other output is possible: when deleting files, the "%i" will output
9a7eef96
WD
559--- old/sender.c
560+++ new/sender.c
1cb60481
WD
561@@ -38,6 +38,7 @@ extern int do_progress;
562 extern int inplace;
563 extern int batch_fd;
564 extern int write_batch;
565+extern unsigned int file_struct_len;
566 extern struct stats stats;
567 extern struct file_list *the_file_list;
568 extern char *log_format;
569@@ -126,7 +127,7 @@ void successful_send(int ndx)
570
571 file = the_file_list->files[ndx];
572 /* The generator might tell us about symlinks we didn't send. */
573- if (!(file->flags & FLAG_SENT) && !S_ISLNK(file->mode))
574+ if (!(FFLAGS(file) & FLAG_SENT) && !S_ISLNK(file->mode))
575 return;
576 if (file->dir.root) {
577 offset = stringjoin(fname, sizeof fname,
578@@ -370,7 +371,7 @@ void send_files(struct file_list *flist,
579 rprintf(FINFO, "sender finished %s\n", fname);
580
581 /* Flag that we actually sent this entry. */
582- file->flags |= FLAG_SENT;
583+ FFLAGS(file) |= FLAG_SENT;
584 }
585 make_backups = save_make_backups;
586
9a7eef96
WD
587--- old/testsuite/atimes.test
588+++ new/testsuite/atimes.test
13bed3dd
WD
589@@ -0,0 +1,19 @@
590+#! /bin/sh
591+
592+# Test rsync copying atimes
593+
594+. "$suitedir/rsync.fns"
595+
596+set -x
597+
598+mkdir "$fromdir"
599+
600+touch "$fromdir/foo"
601+touch -a -t 200102031717.42 "$fromdir/foo"
602+
603+TLS_ARGS=--atime
604+
55602791 605+checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir"
13bed3dd
WD
606+
607+# The script would have aborted on error, so getting here means we've won.
608+exit 0
9a7eef96
WD
609--- old/testsuite/rsync.fns
610+++ new/testsuite/rsync.fns
7a56a8f1
WD
611@@ -66,7 +66,7 @@ printmsg() {
612 }
13bed3dd
WD
613
614 rsync_ls_lR() {
b78a6aba
WD
615- find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls"
616+ find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS
13bed3dd
WD
617 }
618
7a56a8f1
WD
619 check_perms() {
620@@ -184,6 +184,10 @@ checkit() {
13bed3dd
WD
621 # We can just write everything to stdout/stderr, because the
622 # wrapper hides it unless there is a problem.
623
81c32ffd
WD
624+ if test x$TLS_ARGS = x--atime; then
625+ ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
626+ fi
13bed3dd
WD
627+
628 echo "Running: \"$1\""
629 eval "$1"
630 status=$?
7a56a8f1 631@@ -191,10 +195,13 @@ checkit() {
81c32ffd
WD
632 failed="YES";
633 fi
634
635+ if test x$TLS_ARGS != x--atime; then
636+ ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
637+ fi
638+
13bed3dd 639 echo "-------------"
b78a6aba
WD
640 echo "check how the directory listings compare with diff:"
641 echo ""
13bed3dd 642- ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
b78a6aba
WD
643 ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
644 diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
4da25dad 645
9a7eef96
WD
646--- old/tls.c
647+++ new/tls.c
43581f16
WD
648@@ -39,6 +39,7 @@
649
650
651 #include "rsync.h"
652+#include "popt.h"
653
654 #define PROGRAM "tls"
655
656@@ -48,6 +49,7 @@ int read_only = 1;
657 int list_only = 0;
658 int preserve_perms = 0;
659
660+static int display_atime = 0;
661
fe6407b5
WD
662 static void failed(char const *what, char const *where)
663 {
664@@ -56,14 +58,29 @@ static void failed(char const *what, cha
665 exit(1);
43581f16
WD
666 }
667
668+static void storetime(char *dest, time_t t)
669+{
670+ if (t) {
671+ struct tm *mt = gmtime(&t);
672
673+ sprintf(dest, "%04d-%02d-%02d %02d:%02d:%02d ",
9d95bd65
WD
674+ (int)mt->tm_year + 1900,
675+ (int)mt->tm_mon + 1,
676+ (int)mt->tm_mday,
677+ (int)mt->tm_hour,
678+ (int)mt->tm_min,
679+ (int)mt->tm_sec);
43581f16
WD
680+ } else {
681+ strcpy(dest, " ");
682+ }
683+}
684
fe6407b5 685 static void list_file(const char *fname)
43581f16
WD
686 {
687 STRUCT_STAT buf;
688 char permbuf[PERMSTRING_SIZE];
689- struct tm *mt;
690- char datebuf[50];
691+ char mtimebuf[50];
692+ char atimebuf[50];
693 char linkbuf[4096];
694
ba50e96c
WD
695 if (do_lstat(fname, &buf) < 0)
696@@ -96,19 +113,8 @@ static void list_file(const char *fname)
43581f16
WD
697
698 permstring(permbuf, buf.st_mode);
699
700- if (buf.st_mtime) {
701- mt = gmtime(&buf.st_mtime);
702-
703- sprintf(datebuf, "%04d-%02d-%02d %02d:%02d:%02d",
9d95bd65
WD
704- (int)mt->tm_year + 1900,
705- (int)mt->tm_mon + 1,
706- (int)mt->tm_mday,
707- (int)mt->tm_hour,
708- (int)mt->tm_min,
709- (int)mt->tm_sec);
43581f16
WD
710- } else {
711- strcpy(datebuf, " ");
712- }
713+ storetime(mtimebuf, buf.st_mtime);
714+ storetime(atimebuf, buf.st_atime);
715
716 /* TODO: Perhaps escape special characters in fname? */
717
ba50e96c 718@@ -119,24 +125,55 @@ static void list_file(const char *fname)
43581f16
WD
719 (long)minor(buf.st_rdev));
720 } else /* NB: use double for size since it might not fit in a long. */
721 printf("%12.0f", (double)buf.st_size);
722- printf(" %6ld.%-6ld %6ld %s %s%s\n",
723+ printf(" %6ld.%-6ld %6ld %s%s%s%s\n",
724 (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
725- datebuf, fname, linkbuf);
c0be1af2 726+ mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "",
43581f16
WD
727+ fname, linkbuf);
728 }
729
730+static struct poptOption long_options[] = {
731+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
732+ {"atime", 'u', POPT_ARG_NONE, &display_atime, 0, 0, 0},
733+ {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0},
734+ {0,0,0,0,0,0,0}
735+};
736+
737+static void tls_usage(int ret)
738+{
739+ fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n"
740+ "Trivial file listing program for portably checking rsync\n");
741+ exit(ret);
742+}
743
744 int
745 main(int argc, char *argv[])
746 {
747- if (argc < 2) {
fe6407b5
WD
748- fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
749- "Trivial file listing program for portably checking rsync\n");
43581f16
WD
750- return 1;
751+ poptContext pc;
752+ const char **extra_args;
753+ int opt;
754+
755+ pc = poptGetContext(PROGRAM, argc, (const char **)argv,
756+ long_options, 0);
757+ while ((opt = poptGetNextOpt(pc)) != -1) {
758+ switch (opt) {
759+ case 'h':
760+ tls_usage(0);
761+ default:
762+ fprintf(stderr,
763+ "%s: %s\n",
764+ poptBadOption(pc, POPT_BADOPTION_NOALIAS),
765+ poptStrerror(opt));
766+ tls_usage(1);
767+ }
768 }
769
770- for (argv++; *argv; argv++) {
fe6407b5 771- list_file(*argv);
43581f16
WD
772- }
773+ extra_args = poptGetArgs(pc);
774+ if (*extra_args == NULL)
775+ tls_usage(1);
776+
777+ for (; *extra_args; extra_args++)
778+ list_file(*extra_args);
779+ poptFreeContext(pc);
780
781 return 0;
782 }
9a7eef96
WD
783--- old/util.c
784+++ new/util.c
d9a67109 785@@ -126,7 +126,7 @@ void overflow_exit(char *str)
577db5e2
WD
786 exit_cleanup(RERR_MALLOC);
787 }
43581f16 788
9e355bf1
WD
789-int set_modtime(char *fname, time_t modtime, mode_t mode)
790+int set_times(char *fname, time_t modtime, time_t atime, mode_t mode)
43581f16 791 {
9e355bf1
WD
792 #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
793 if (S_ISLNK(mode))
d9a67109 794@@ -134,9 +134,13 @@ int set_modtime(char *fname, time_t modt
9e355bf1
WD
795 #endif
796
43581f16
WD
797 if (verbose > 2) {
798- rprintf(FINFO, "set modtime of %s to (%ld) %s",
799+ char mtimebuf[200];
43581f16 800+
125d7fca 801+ strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf);
43581f16
WD
802+ rprintf(FINFO,
803+ "set modtime, atime of %s to (%ld) %s, (%ld) %s\n",
93ca4d27 804 fname, (long)modtime,
43581f16 805- asctime(localtime(&modtime)));
9e355bf1 806+ mtimebuf, (long)atime, timestring(atime));
43581f16
WD
807 }
808
ba50e96c 809 if (dry_run)
d9a67109 810@@ -145,7 +149,7 @@ int set_modtime(char *fname, time_t modt
43581f16 811 {
9e355bf1
WD
812 #ifdef HAVE_UTIMES
813 struct timeval t[2];
814- t[0].tv_sec = time(NULL);
815+ t[0].tv_sec = atime;
816 t[0].tv_usec = 0;
817 t[1].tv_sec = modtime;
818 t[1].tv_usec = 0;
d9a67109 819@@ -156,12 +160,12 @@ int set_modtime(char *fname, time_t modt
9e355bf1
WD
820 return utimes(fname, t);
821 #elif defined HAVE_UTIMBUF
43581f16
WD
822 struct utimbuf tbuf;
823- tbuf.actime = time(NULL);
824+ tbuf.actime = atime;
825 tbuf.modtime = modtime;
826 return utime(fname,&tbuf);
09fb8f03 827 #elif defined HAVE_UTIME
43581f16
WD
828 time_t t[2];
829- t[0] = time(NULL);
830+ t[0] = atime;
831 t[1] = modtime;
832 return utime(fname,t);
833 #else