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