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