Commit | Line | Data |
---|---|---|
03019e41 | 1 | To use this patch, run these commands for a successful build: |
8a529471 | 2 | |
03019e41 | 3 | patch -p1 <patches/atimes.diff |
27e96866 WD |
4 | ./prepare-source |
5 | ./configure (optional if already run) | |
6 | make | |
8a529471 WD |
7 | |
8 | ||
9a7eef96 WD |
9 | --- old/flist.c |
10 | +++ new/flist.c | |
b3593e7c | 11 | @@ -46,6 +46,7 @@ extern int preserve_devices; |
4a65fe72 | 12 | extern int preserve_specials; |
81c32ffd WD |
13 | extern int preserve_uid; |
14 | extern int preserve_gid; | |
15 | +extern int preserve_atimes; | |
16 | extern int relative_paths; | |
a5e0f697 | 17 | extern int implied_dirs; |
1aa236e1 WD |
18 | extern int flist_extra_cnt; |
19 | @@ -134,6 +135,7 @@ void show_flist_stats(void) | |
672ad041 WD |
20 | static void list_file_entry(struct file_struct *f) |
21 | { | |
22 | char permbuf[PERMSTRING_SIZE]; | |
70891d26 | 23 | + time_t atime = preserve_atimes ? F_ATIME(f) : 0; |
1aa236e1 | 24 | double len; |
1cb60481 | 25 | |
1aa236e1 WD |
26 | if (!F_IS_ACTIVE(f)) { |
27 | @@ -146,14 +148,16 @@ static void list_file_entry(struct file_ | |
43581f16 | 28 | |
09fb8f03 | 29 | #ifdef SUPPORT_LINKS |
43581f16 WD |
30 | if (preserve_links && S_ISLNK(f->mode)) { |
31 | - rprintf(FINFO, "%s %11.0f %s %s -> %s\n", | |
32 | + rprintf(FINFO, "%s %11.0f %s %s %s -> %s\n", | |
1aa236e1 | 33 | permbuf, len, timestring(f->modtime), |
672ad041 | 34 | + preserve_atimes ? timestring(atime) : "", |
70891d26 | 35 | f_name(f, NULL), F_SYMLINK(f)); |
43581f16 WD |
36 | } else |
37 | #endif | |
896c61d0 | 38 | { |
43581f16 WD |
39 | - rprintf(FINFO, "%s %11.0f %s %s\n", |
40 | + rprintf(FINFO, "%s %11.0f %s %s %s\n", | |
1aa236e1 | 41 | permbuf, len, timestring(f->modtime), |
672ad041 | 42 | + preserve_atimes ? timestring(atime) : "", |
bd68c3c2 | 43 | f_name(f, NULL)); |
896c61d0 | 44 | } |
43581f16 | 45 | } |
1aa236e1 | 46 | @@ -311,6 +315,7 @@ static void send_file_entry(struct file_ |
43581f16 WD |
47 | { |
48 | unsigned short flags; | |
49 | static time_t modtime; | |
50 | + static time_t atime; | |
51 | static mode_t mode; | |
ba50e96c | 52 | static int64 dev; |
43581f16 | 53 | static dev_t rdev; |
1aa236e1 | 54 | @@ -326,7 +331,7 @@ static void send_file_entry(struct file_ |
43581f16 WD |
55 | |
56 | if (!file) { | |
57 | write_byte(f, 0); | |
58 | - modtime = 0, mode = 0; | |
59 | + modtime = 0, atime = 0, mode = 0; | |
d9f0e41c | 60 | dev = 0, rdev = MAKEDEV(0, 0); |
43581f16 WD |
61 | rdev_major = 0; |
62 | uid = 0, gid = 0; | |
1aa236e1 | 63 | @@ -376,6 +381,13 @@ static void send_file_entry(struct file_ |
43581f16 WD |
64 | flags |= XMIT_SAME_TIME; |
65 | else | |
66 | modtime = file->modtime; | |
81c32ffd | 67 | + if (preserve_atimes && !S_ISDIR(mode)) { |
70891d26 | 68 | + time_t file_atime = F_ATIME(file); |
672ad041 | 69 | + if (file_atime == atime) |
43581f16 WD |
70 | + flags |= XMIT_SAME_ATIME; |
71 | + else | |
672ad041 | 72 | + atime = file_atime; |
43581f16 WD |
73 | + } |
74 | ||
09fb8f03 | 75 | #ifdef SUPPORT_HARD_LINKS |
70891d26 | 76 | if (tmp_idev.dev != 0) { |
1aa236e1 | 77 | @@ -428,6 +440,8 @@ static void send_file_entry(struct file_ |
43581f16 WD |
78 | write_int(f, modtime); |
79 | if (!(flags & XMIT_SAME_MODE)) | |
80 | write_int(f, to_wire_mode(mode)); | |
81c32ffd | 81 | + if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME)) |
43581f16 WD |
82 | + write_int(f, atime); |
83 | if (preserve_uid && !(flags & XMIT_SAME_UID)) { | |
84 | if (!numeric_ids) | |
85 | add_uid(uid); | |
1aa236e1 | 86 | @@ -494,7 +508,7 @@ static void send_file_entry(struct file_ |
70891d26 WD |
87 | static struct file_struct *recv_file_entry(struct file_list *flist, |
88 | unsigned short flags, int f) | |
43581f16 | 89 | { |
70891d26 WD |
90 | - static time_t modtime; |
91 | + static time_t modtime, atime; | |
43581f16 | 92 | static mode_t mode; |
ba50e96c | 93 | static int64 dev; |
43581f16 | 94 | static dev_t rdev; |
1aa236e1 | 95 | @@ -514,7 +528,7 @@ static struct file_struct *recv_file_ent |
43581f16 WD |
96 | struct file_struct *file; |
97 | ||
a7219d20 | 98 | if (!flist) { |
43581f16 WD |
99 | - modtime = 0, mode = 0; |
100 | + modtime = 0, atime = 0, mode = 0; | |
d9f0e41c | 101 | dev = 0, rdev = MAKEDEV(0, 0); |
43581f16 WD |
102 | rdev_major = 0; |
103 | uid = 0, gid = 0; | |
1aa236e1 | 104 | @@ -570,6 +584,8 @@ static struct file_struct *recv_file_ent |
43581f16 WD |
105 | modtime = (time_t)read_int(f); |
106 | if (!(flags & XMIT_SAME_MODE)) | |
107 | mode = from_wire_mode(read_int(f)); | |
81c32ffd | 108 | + if (preserve_atimes && !S_ISDIR(mode) && !(flags & XMIT_SAME_ATIME)) |
43581f16 WD |
109 | + atime = (time_t)read_int(f); |
110 | ||
1cb60481 WD |
111 | if (chmod_modes && !S_ISLNK(mode)) |
112 | mode = tweak_mode(mode, chmod_modes); | |
1aa236e1 | 113 | @@ -654,6 +670,8 @@ static struct file_struct *recv_file_ent |
70891d26 WD |
114 | F_UID(file) = uid; |
115 | if (preserve_gid) | |
116 | F_GID(file) = gid; | |
1cb60481 | 117 | + if (preserve_atimes) |
70891d26 | 118 | + F_ATIME(file) = atime; |
1cb60481 WD |
119 | |
120 | if (dirname_len) { | |
121 | file->dirname = lastdir = bp; | |
1071853f | 122 | @@ -931,6 +949,8 @@ struct file_struct *make_file(const char |
70891d26 WD |
123 | F_UID(file) = st.st_uid; |
124 | if (preserve_gid) | |
125 | F_GID(file) = st.st_gid; | |
1cb60481 | 126 | + if (preserve_atimes) |
70891d26 | 127 | + F_ATIME(file) = st.st_atime; |
1cb60481 | 128 | |
70891d26 WD |
129 | if (dirname_len) { |
130 | file->dirname = lastdir = bp; | |
9a7eef96 WD |
131 | --- old/generator.c |
132 | +++ new/generator.c | |
195ca26e | 133 | @@ -43,6 +43,7 @@ extern int preserve_perms; |
55602791 | 134 | extern int preserve_uid; |
81c32ffd WD |
135 | extern int preserve_gid; |
136 | extern int preserve_times; | |
81c32ffd | 137 | +extern int preserve_atimes; |
55602791 | 138 | extern int omit_dir_times; |
4a65fe72 | 139 | extern int delete_mode; |
81c32ffd | 140 | extern int delete_before; |
1071853f | 141 | @@ -547,6 +548,9 @@ void itemize(struct file_struct *file, i |
9a70b743 WD |
142 | && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) |
143 | || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0)) | |
f20eb450 | 144 | iflags |= ITEM_REPORT_TIME; |
55602791 | 145 | + if (preserve_atimes && !S_ISDIR(file->mode) && !S_ISLNK(file->mode) |
70891d26 | 146 | + && cmp_time(F_ATIME(file), st->st_atime) != 0) |
55602791 | 147 | + iflags |= ITEM_REPORT_ATIME; |
1071853f | 148 | if ((unsigned)(st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) |
f20eb450 | 149 | iflags |= ITEM_REPORT_PERMS; |
70891d26 | 150 | if (preserve_uid && am_root && F_UID(file) != st->st_uid) |
1071853f | 151 | @@ -859,6 +863,8 @@ static int try_dests_reg(struct file_str |
9a70b743 WD |
152 | if (hard_link_one(file, ndx, fname, 0, stp, |
153 | cmpbuf, 1, i, code) < 0) | |
8a04c9a7 WD |
154 | goto try_a_copy; |
155 | + if (preserve_atimes) | |
4a65fe72 | 156 | + set_file_attrs(fname, file, stp, 0); |
1aa236e1 | 157 | if (preserve_hard_links && F_IS_HLINKED(file)) |
70891d26 WD |
158 | hard_link_cluster(file, ndx, itemizing, code, j); |
159 | } else | |
9a7eef96 WD |
160 | --- old/log.c |
161 | +++ new/log.c | |
b3593e7c | 162 | @@ -37,6 +37,7 @@ extern int msg_fd_out; |
577db5e2 | 163 | extern int allow_8bit_chars; |
81c32ffd WD |
164 | extern int protocol_version; |
165 | extern int preserve_times; | |
166 | +extern int preserve_atimes; | |
70891d26 WD |
167 | extern int preserve_uid; |
168 | extern int preserve_gid; | |
1aa236e1 WD |
169 | extern int stdout_format_has_i; |
170 | @@ -625,7 +626,8 @@ static void log_formatted(enum logcode c | |
fb11cdd7 WD |
171 | c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p'; |
172 | c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o'; | |
173 | c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g'; | |
174 | - c[8] = '.'; | |
175 | + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' | |
55602791 | 176 | + : S_ISLNK(file->mode) ? 'U' : 'u'; |
fb11cdd7 | 177 | c[9] = '\0'; |
81c32ffd WD |
178 | |
179 | if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) { | |
9a7eef96 WD |
180 | --- old/options.c |
181 | +++ new/options.c | |
b3593e7c | 182 | @@ -55,6 +55,7 @@ int preserve_uid = 0; |
43581f16 WD |
183 | int preserve_gid = 0; |
184 | int preserve_times = 0; | |
9a21ad72 | 185 | int omit_dir_times = 0; |
81c32ffd | 186 | +int preserve_atimes = 0; |
43581f16 WD |
187 | int update_only = 0; |
188 | int cvs_exclude = 0; | |
189 | int dry_run = 0; | |
70891d26 | 190 | @@ -307,8 +308,9 @@ void usage(enum logcode F) |
4a65fe72 WD |
191 | rprintf(F," --devices preserve device files (super-user only)\n"); |
192 | rprintf(F," --specials preserve special files\n"); | |
193 | rprintf(F," -D same as --devices --specials\n"); | |
81c32ffd WD |
194 | - rprintf(F," -t, --times preserve times\n"); |
195 | - rprintf(F," -O, --omit-dir-times omit directories when preserving times\n"); | |
196 | + rprintf(F," -t, --times preserve modify times\n"); | |
197 | + rprintf(F," -O, --omit-dir-times omit directories when preserving modify times\n"); | |
55602791 | 198 | + rprintf(F," -U, --atimes preserve access (use) times\n"); |
4a65fe72 | 199 | rprintf(F," --super receiver attempts super-user activities\n"); |
43581f16 WD |
200 | rprintf(F," -S, --sparse handle sparse files efficiently\n"); |
201 | rprintf(F," -n, --dry-run show what would have been transferred\n"); | |
70891d26 | 202 | @@ -425,6 +427,9 @@ static struct poptOption long_options[] |
489b0a72 WD |
203 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, |
204 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
205 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
55602791 | 206 | + {"atimes", 'U', POPT_ARG_VAL, &preserve_atimes, 1, 0, 0 }, |
489b0a72 | 207 | + {"no-atimes", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 }, |
70891d26 | 208 | + {"no-U", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 }, |
52f25864 | 209 | {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 2, 0, 0 }, |
489b0a72 | 210 | {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 }, |
4a65fe72 | 211 | {"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 }, |
70891d26 | 212 | @@ -1223,6 +1228,8 @@ int parse_arguments(int *argc, const cha |
1aa236e1 | 213 | preserve_uid = ++flist_extra_cnt; |
70891d26 | 214 | if (preserve_gid) |
1aa236e1 | 215 | preserve_gid = ++flist_extra_cnt; |
70891d26 | 216 | + if (preserve_atimes) |
1aa236e1 | 217 | + preserve_atimes = ++flist_extra_cnt; |
70891d26 WD |
218 | |
219 | *argv = poptGetArgs(pc); | |
220 | *argc = count_args(*argv); | |
221 | @@ -1542,6 +1549,8 @@ void server_options(char **args,int *arg | |
43581f16 WD |
222 | argstr[x++] = 'D'; |
223 | if (preserve_times) | |
224 | argstr[x++] = 't'; | |
81c32ffd | 225 | + if (preserve_atimes) |
55602791 | 226 | + argstr[x++] = 'U'; |
43581f16 | 227 | if (preserve_perms) |
4a65fe72 WD |
228 | argstr[x++] = 'p'; |
229 | else if (preserve_executability && am_sender) | |
9a7eef96 WD |
230 | --- old/rsync.c |
231 | +++ new/rsync.c | |
195ca26e WD |
232 | @@ -34,6 +34,7 @@ extern int verbose; |
233 | extern int dry_run; | |
d9a67109 | 234 | extern int preserve_perms; |
4a65fe72 | 235 | extern int preserve_executability; |
d9a67109 | 236 | +extern int preserve_atimes; |
43581f16 | 237 | extern int preserve_times; |
9a21ad72 | 238 | extern int omit_dir_times; |
43581f16 | 239 | extern int am_root; |
70891d26 | 240 | @@ -182,6 +183,7 @@ int set_file_attrs(char *fname, struct f |
9a21ad72 WD |
241 | int updated = 0; |
242 | STRUCT_STAT st2; | |
243 | int change_uid, change_gid; | |
244 | + time_t atime, mtime; | |
1ed0b5c9 | 245 | mode_t new_mode = file->mode; |
9a21ad72 WD |
246 | |
247 | if (!st) { | |
70891d26 | 248 | @@ -201,18 +203,36 @@ int set_file_attrs(char *fname, struct f |
7a56a8f1 | 249 | } |
8a04c9a7 | 250 | } |
9a21ad72 | 251 | |
8a04c9a7 WD |
252 | + /* This code must be the first update in the function due to |
253 | + * how it uses the "updated" variable. */ | |
9e355bf1 | 254 | if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times)) |
4a65fe72 | 255 | flags |= ATTRS_SKIP_MTIME; |
81c32ffd | 256 | + if (!preserve_atimes || S_ISDIR(st->st_mode)) |
4a65fe72 WD |
257 | + flags |= ATTRS_SKIP_ATIME; |
258 | if (!(flags & ATTRS_SKIP_MTIME) | |
577db5e2 | 259 | && cmp_time(st->st_mtime, file->modtime) != 0) { |
9e355bf1 | 260 | - int ret = set_modtime(fname, file->modtime, st->st_mode); |
9a21ad72 | 261 | + mtime = file->modtime; |
9e355bf1 | 262 | + updated = 1; |
9a21ad72 WD |
263 | + } else |
264 | + mtime = st->st_mtime; | |
672ad041 | 265 | + if (!(flags & ATTRS_SKIP_ATIME)) { |
70891d26 | 266 | + time_t file_atime = F_ATIME(file); |
672ad041 WD |
267 | + if (cmp_time(st->st_atime, file_atime) != 0) { |
268 | + atime = file_atime; | |
269 | + updated = 1; | |
270 | + } else | |
271 | + atime = st->st_atime; | |
81c32ffd WD |
272 | + } else |
273 | + atime = st->st_atime; | |
9e355bf1 WD |
274 | + if (updated) { |
275 | + int ret = set_times(fname, mtime, atime, st->st_mode); | |
276 | if (ret < 0) { | |
277 | rsyserr(FERROR, errno, "failed to set times on %s", | |
278 | full_fname(fname)); | |
279 | return 0; | |
280 | } | |
281 | - if (ret == 0) /* ret == 1 if symlink could not be set */ | |
282 | - updated = 1; | |
283 | + if (ret > 0) /* ret == 1 if symlink could not be set */ | |
284 | + updated = 0; | |
43581f16 WD |
285 | } |
286 | ||
70891d26 | 287 | change_uid = am_root && preserve_uid && st->st_uid != F_UID(file); |
9a7eef96 WD |
288 | --- old/rsync.h |
289 | +++ new/rsync.h | |
43581f16 WD |
290 | @@ -54,6 +54,7 @@ |
291 | #define XMIT_HAS_IDEV_DATA (1<<9) | |
292 | #define XMIT_SAME_DEV (1<<10) | |
293 | #define XMIT_RDEV_MINOR_IS_SMALL (1<<11) | |
294 | +#define XMIT_SAME_ATIME (1<<12) | |
295 | ||
296 | /* These flags are used in the live flist data. */ | |
297 | ||
1aa236e1 | 298 | @@ -121,6 +122,7 @@ |
8a529471 | 299 | |
4a65fe72 WD |
300 | #define ATTRS_REPORT (1<<0) |
301 | #define ATTRS_SKIP_MTIME (1<<1) | |
302 | +#define ATTRS_SKIP_ATIME (1<<2) | |
8a529471 WD |
303 | |
304 | #define FULL_FLUSH 1 | |
305 | #define NORMAL_FLUSH 0 | |
1aa236e1 WD |
306 | @@ -511,6 +513,7 @@ struct file_struct { |
307 | union flist_extras { | |
308 | uid_t uid; /* The user ID number */ | |
309 | uid_t gid; /* The group ID number or GID_NONE */ | |
310 | + time_t utime; /* A unix-time value */ | |
311 | struct idev *idev; /* The hard-link info during matching */ | |
312 | struct hlist *hlist; /* The hard-link info after matching */ | |
1071853f WD |
313 | int32 num; /* A signed number */ |
314 | @@ -553,6 +556,7 @@ extern int preserve_gid; | |
1aa236e1 WD |
315 | /* When the associated option is on, all entries will have these present: */ |
316 | #define F_UID(f) REQ_EXTRA(f, preserve_uid)->uid | |
317 | #define F_GID(f) REQ_EXTRA(f, preserve_gid)->gid | |
318 | +#define F_ATIME(f) REQ_EXTRA(f, preserve_atimes)->utime | |
70891d26 | 319 | |
1071853f WD |
320 | /* These items are per-entry optional and mutally exclusive: */ |
321 | #define F_HL_IDEV(f) OPT_EXTRA(f, LEN64_BUMP(f))->idev | |
9a7eef96 WD |
322 | --- old/rsync.yo |
323 | +++ new/rsync.yo | |
03019e41 | 324 | @@ -328,8 +328,9 @@ to the detailed description below for a |
4a65fe72 WD |
325 | --devices preserve device files (super-user only) |
326 | --specials preserve special files | |
327 | -D same as --devices --specials | |
81c32ffd | 328 | - -t, --times preserve times |
610969d1 | 329 | - -O, --omit-dir-times omit directories when preserving times |
81c32ffd | 330 | + -t, --times preserve modify times |
610969d1 | 331 | + -O, --omit-dir-times omit directories when preserving mod-times |
55602791 | 332 | + -U, --atimes preserve access (use) times |
4a65fe72 | 333 | --super receiver attempts super-user activities |
43581f16 WD |
334 | -S, --sparse handle sparse files efficiently |
335 | -n, --dry-run show what would have been transferred | |
70891d26 | 336 | @@ -870,6 +871,12 @@ it is preserving modification times (see |
a7219d20 | 337 | the directories on the receiving side, it is a good idea to use bf(-O). |
333b8af4 | 338 | This option is inferred if you use bf(--backup) without bf(--backup-dir). |
7b675ff5 | 339 | |
55602791 WD |
340 | +dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the |
341 | +destination files to the same value as the source files. Note that the | |
81c32ffd WD |
342 | +reading of the source file may update the atime of the source files, so |
343 | +repeated rsync runs with --atimes may be needed if you want to force the | |
344 | +access-time values to be 100% identical on the two systems. | |
7b675ff5 | 345 | + |
4a65fe72 WD |
346 | dit(bf(--super)) This tells the receiving side to attempt super-user |
347 | activities even if the receiving rsync wasn't run by the super-user. These | |
348 | activities include: preserving users via the bf(--owner) option, preserving | |
70891d26 | 349 | @@ -1403,7 +1410,7 @@ with older versions of rsync, but that a |
4a65fe72 WD |
350 | verbose messages). |
351 | ||
ccc3a12c WD |
352 | The "%i" escape has a cryptic output that is 9 letters long. The general |
353 | -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the | |
354 | +format is like the string bf(YXcstpogu), where bf(Y) is replaced by the | |
355 | type of update being done, bf(X) is replaced by the file-type, and the | |
4a65fe72 WD |
356 | other letters represent attributes that may be output if they are being |
357 | modified. | |
70891d26 | 358 | @@ -1443,7 +1450,7 @@ quote(itemization( |
81c32ffd WD |
359 | by the file transfer. |
360 | it() A bf(t) means the modification time is different and is being updated | |
361 | to the sender's value (requires bf(--times)). An alternate value of bf(T) | |
362 | - means that the time will be set to the transfer time, which happens | |
363 | + means that the modify time will be set to the transfer time, which happens | |
364 | anytime a symlink is transferred, or when a file or device is transferred | |
365 | without bf(--times). | |
ccc3a12c | 366 | it() A bf(p) means the permissions are different and are being updated to |
70891d26 | 367 | @@ -1452,7 +1459,10 @@ quote(itemization( |
ccc3a12c WD |
368 | sender's value (requires bf(--owner) and super-user privileges). |
369 | it() A bf(g) means the group is different and is being updated to the | |
370 | sender's value (requires bf(--group) and the authority to set the group). | |
371 | - it() The bf(z) slot is reserved for future use. | |
55602791 WD |
372 | + it() A bf(u) means the access (use) time is different and is being updated to |
373 | + the sender's value (requires bf(--atimes)). An alternate value of bf(U) | |
374 | + means that the access time will be set to the transfer time, which happens | |
ccc3a12c WD |
375 | + when a symlink or directory is updated. |
376 | )) | |
377 | ||
378 | One other output is possible: when deleting files, the "%i" will output | |
9a7eef96 WD |
379 | --- old/sender.c |
380 | +++ new/sender.c | |
b3593e7c | 381 | @@ -41,6 +41,7 @@ extern int do_progress; |
1cb60481 WD |
382 | extern int inplace; |
383 | extern int batch_fd; | |
384 | extern int write_batch; | |
385 | +extern unsigned int file_struct_len; | |
386 | extern struct stats stats; | |
387 | extern struct file_list *the_file_list; | |
a859733e | 388 | extern char *stdout_format; |
9a7eef96 WD |
389 | --- old/testsuite/atimes.test |
390 | +++ new/testsuite/atimes.test | |
13bed3dd WD |
391 | @@ -0,0 +1,19 @@ |
392 | +#! /bin/sh | |
393 | + | |
394 | +# Test rsync copying atimes | |
395 | + | |
396 | +. "$suitedir/rsync.fns" | |
397 | + | |
398 | +set -x | |
399 | + | |
400 | +mkdir "$fromdir" | |
401 | + | |
402 | +touch "$fromdir/foo" | |
403 | +touch -a -t 200102031717.42 "$fromdir/foo" | |
404 | + | |
405 | +TLS_ARGS=--atime | |
406 | + | |
55602791 | 407 | +checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" |
13bed3dd WD |
408 | + |
409 | +# The script would have aborted on error, so getting here means we've won. | |
410 | +exit 0 | |
9a7eef96 WD |
411 | --- old/testsuite/rsync.fns |
412 | +++ new/testsuite/rsync.fns | |
7a56a8f1 WD |
413 | @@ -66,7 +66,7 @@ printmsg() { |
414 | } | |
13bed3dd WD |
415 | |
416 | rsync_ls_lR() { | |
b78a6aba WD |
417 | - find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" |
418 | + find "$@" -print | sort | sed 's/ /\\ /g' | xargs "$TOOLDIR/tls" $TLS_ARGS | |
13bed3dd WD |
419 | } |
420 | ||
7a56a8f1 WD |
421 | check_perms() { |
422 | @@ -184,6 +184,10 @@ checkit() { | |
13bed3dd WD |
423 | # We can just write everything to stdout/stderr, because the |
424 | # wrapper hides it unless there is a problem. | |
425 | ||
81c32ffd WD |
426 | + if test x$TLS_ARGS = x--atime; then |
427 | + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from" | |
428 | + fi | |
13bed3dd WD |
429 | + |
430 | echo "Running: \"$1\"" | |
431 | eval "$1" | |
432 | status=$? | |
7a56a8f1 | 433 | @@ -191,10 +195,13 @@ checkit() { |
81c32ffd WD |
434 | failed="YES"; |
435 | fi | |
436 | ||
437 | + if test x$TLS_ARGS != x--atime; then | |
438 | + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from" | |
439 | + fi | |
440 | + | |
13bed3dd | 441 | echo "-------------" |
b78a6aba WD |
442 | echo "check how the directory listings compare with diff:" |
443 | echo "" | |
13bed3dd | 444 | - ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from" |
b78a6aba WD |
445 | ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to" |
446 | diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES | |
4da25dad | 447 | |
9a7eef96 WD |
448 | --- old/tls.c |
449 | +++ new/tls.c | |
b3593e7c WD |
450 | @@ -34,6 +34,7 @@ |
451 | * change. */ | |
43581f16 WD |
452 | |
453 | #include "rsync.h" | |
454 | +#include "popt.h" | |
455 | ||
456 | #define PROGRAM "tls" | |
457 | ||
b3593e7c | 458 | @@ -43,6 +44,8 @@ int read_only = 1; |
43581f16 WD |
459 | int list_only = 0; |
460 | int preserve_perms = 0; | |
461 | ||
462 | +static int display_atime = 0; | |
b3593e7c | 463 | + |
fe6407b5 WD |
464 | static void failed(char const *what, char const *where) |
465 | { | |
b3593e7c WD |
466 | fprintf(stderr, PROGRAM ": %s %s: %s\n", |
467 | @@ -50,12 +53,29 @@ static void failed(char const *what, cha | |
fe6407b5 | 468 | exit(1); |
43581f16 WD |
469 | } |
470 | ||
3f053c45 | 471 | +static void storetime(char *dest, time_t t, size_t destsize) |
43581f16 WD |
472 | +{ |
473 | + if (t) { | |
474 | + struct tm *mt = gmtime(&t); | |
b3593e7c | 475 | + |
3f053c45 WD |
476 | + snprintf(dest, destsize, |
477 | + "%04d-%02d-%02d %02d:%02d:%02d ", | |
9d95bd65 WD |
478 | + (int)mt->tm_year + 1900, |
479 | + (int)mt->tm_mon + 1, | |
480 | + (int)mt->tm_mday, | |
481 | + (int)mt->tm_hour, | |
482 | + (int)mt->tm_min, | |
483 | + (int)mt->tm_sec); | |
3f053c45 WD |
484 | + } else |
485 | + strlcpy(dest, " ", destsize); | |
b3593e7c WD |
486 | +} |
487 | + | |
fe6407b5 | 488 | static void list_file(const char *fname) |
43581f16 WD |
489 | { |
490 | STRUCT_STAT buf; | |
491 | char permbuf[PERMSTRING_SIZE]; | |
492 | - struct tm *mt; | |
493 | - char datebuf[50]; | |
494 | + char mtimebuf[50]; | |
495 | + char atimebuf[50]; | |
496 | char linkbuf[4096]; | |
497 | ||
ba50e96c | 498 | if (do_lstat(fname, &buf) < 0) |
b3593e7c | 499 | @@ -88,19 +108,8 @@ static void list_file(const char *fname) |
43581f16 WD |
500 | |
501 | permstring(permbuf, buf.st_mode); | |
502 | ||
503 | - if (buf.st_mtime) { | |
504 | - mt = gmtime(&buf.st_mtime); | |
505 | - | |
3f053c45 WD |
506 | - snprintf(datebuf, sizeof datebuf, |
507 | - "%04d-%02d-%02d %02d:%02d:%02d", | |
9d95bd65 WD |
508 | - (int)mt->tm_year + 1900, |
509 | - (int)mt->tm_mon + 1, | |
510 | - (int)mt->tm_mday, | |
511 | - (int)mt->tm_hour, | |
512 | - (int)mt->tm_min, | |
513 | - (int)mt->tm_sec); | |
3f053c45 WD |
514 | - } else |
515 | - strlcpy(datebuf, " ", sizeof datebuf); | |
516 | + storetime(mtimebuf, buf.st_mtime, sizeof mtimebuf); | |
517 | + storetime(atimebuf, buf.st_atime, sizeof atimebuf); | |
43581f16 WD |
518 | |
519 | /* TODO: Perhaps escape special characters in fname? */ | |
520 | ||
b3593e7c | 521 | @@ -111,23 +120,55 @@ static void list_file(const char *fname) |
43581f16 WD |
522 | (long)minor(buf.st_rdev)); |
523 | } else /* NB: use double for size since it might not fit in a long. */ | |
524 | printf("%12.0f", (double)buf.st_size); | |
525 | - printf(" %6ld.%-6ld %6ld %s %s%s\n", | |
526 | + printf(" %6ld.%-6ld %6ld %s%s%s%s\n", | |
527 | (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink, | |
528 | - datebuf, fname, linkbuf); | |
c0be1af2 | 529 | + mtimebuf, display_atime && !S_ISDIR(buf.st_mode) ? atimebuf : "", |
43581f16 | 530 | + fname, linkbuf); |
b3593e7c WD |
531 | +} |
532 | + | |
43581f16 WD |
533 | +static struct poptOption long_options[] = { |
534 | + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
535 | + {"atime", 'u', POPT_ARG_NONE, &display_atime, 0, 0, 0}, | |
536 | + {"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0}, | |
537 | + {0,0,0,0,0,0,0} | |
538 | +}; | |
539 | + | |
540 | +static void tls_usage(int ret) | |
541 | +{ | |
542 | + fprintf(stderr, "usage: " PROGRAM " [--atime | -u] DIR ...\n" | |
543 | + "Trivial file listing program for portably checking rsync\n"); | |
544 | + exit(ret); | |
b3593e7c | 545 | } |
43581f16 WD |
546 | |
547 | int | |
548 | main(int argc, char *argv[]) | |
549 | { | |
550 | - if (argc < 2) { | |
fe6407b5 WD |
551 | - fprintf(stderr, "usage: " PROGRAM " DIR ...\n" |
552 | - "Trivial file listing program for portably checking rsync\n"); | |
43581f16 | 553 | - return 1; |
03019e41 | 554 | - } |
43581f16 WD |
555 | + poptContext pc; |
556 | + const char **extra_args; | |
557 | + int opt; | |
03019e41 WD |
558 | |
559 | - for (argv++; *argv; argv++) { | |
560 | - list_file(*argv); | |
43581f16 WD |
561 | + pc = poptGetContext(PROGRAM, argc, (const char **)argv, |
562 | + long_options, 0); | |
563 | + while ((opt = poptGetNextOpt(pc)) != -1) { | |
564 | + switch (opt) { | |
565 | + case 'h': | |
566 | + tls_usage(0); | |
567 | + default: | |
568 | + fprintf(stderr, | |
569 | + "%s: %s\n", | |
570 | + poptBadOption(pc, POPT_BADOPTION_NOALIAS), | |
571 | + poptStrerror(opt)); | |
572 | + tls_usage(1); | |
573 | + } | |
574 | } | |
575 | ||
43581f16 WD |
576 | + extra_args = poptGetArgs(pc); |
577 | + if (*extra_args == NULL) | |
578 | + tls_usage(1); | |
579 | + | |
580 | + for (; *extra_args; extra_args++) | |
581 | + list_file(*extra_args); | |
582 | + poptFreeContext(pc); | |
03019e41 | 583 | + |
43581f16 WD |
584 | return 0; |
585 | } | |
9a7eef96 WD |
586 | --- old/util.c |
587 | +++ new/util.c | |
fb11cdd7 | 588 | @@ -121,7 +121,7 @@ NORETURN void overflow_exit(const char * |
577db5e2 WD |
589 | exit_cleanup(RERR_MALLOC); |
590 | } | |
43581f16 | 591 | |
fb11cdd7 WD |
592 | -int set_modtime(const char *fname, time_t modtime, mode_t mode) |
593 | +int set_times(const char *fname, time_t modtime, time_t atime, mode_t mode) | |
43581f16 | 594 | { |
9e355bf1 WD |
595 | #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES |
596 | if (S_ISLNK(mode)) | |
fb11cdd7 | 597 | @@ -129,9 +129,13 @@ int set_modtime(const char *fname, time_ |
9e355bf1 WD |
598 | #endif |
599 | ||
43581f16 WD |
600 | if (verbose > 2) { |
601 | - rprintf(FINFO, "set modtime of %s to (%ld) %s", | |
602 | + char mtimebuf[200]; | |
43581f16 | 603 | + |
125d7fca | 604 | + strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf); |
43581f16 WD |
605 | + rprintf(FINFO, |
606 | + "set modtime, atime of %s to (%ld) %s, (%ld) %s\n", | |
93ca4d27 | 607 | fname, (long)modtime, |
43581f16 | 608 | - asctime(localtime(&modtime))); |
9e355bf1 | 609 | + mtimebuf, (long)atime, timestring(atime)); |
43581f16 WD |
610 | } |
611 | ||
ba50e96c | 612 | if (dry_run) |
fb11cdd7 | 613 | @@ -140,7 +144,7 @@ int set_modtime(const char *fname, time_ |
43581f16 | 614 | { |
9e355bf1 WD |
615 | #ifdef HAVE_UTIMES |
616 | struct timeval t[2]; | |
617 | - t[0].tv_sec = time(NULL); | |
618 | + t[0].tv_sec = atime; | |
619 | t[0].tv_usec = 0; | |
620 | t[1].tv_sec = modtime; | |
621 | t[1].tv_usec = 0; | |
fb11cdd7 | 622 | @@ -153,12 +157,12 @@ int set_modtime(const char *fname, time_ |
9e355bf1 WD |
623 | return utimes(fname, t); |
624 | #elif defined HAVE_UTIMBUF | |
43581f16 WD |
625 | struct utimbuf tbuf; |
626 | - tbuf.actime = time(NULL); | |
627 | + tbuf.actime = atime; | |
628 | tbuf.modtime = modtime; | |
629 | return utime(fname,&tbuf); | |
09fb8f03 | 630 | #elif defined HAVE_UTIME |
43581f16 WD |
631 | time_t t[2]; |
632 | - t[0] = time(NULL); | |
633 | + t[0] = atime; | |
634 | t[1] = modtime; | |
635 | return utime(fname,t); | |
636 | #else |