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