| 1 | To use this patch, run these commands for a successful build: |
| 2 | |
| 3 | patch -p1 <patches/atimes.diff |
| 4 | ./configure (optional if already run) |
| 5 | make |
| 6 | |
| 7 | diff --git a/compat.c b/compat.c |
| 8 | --- a/compat.c |
| 9 | +++ b/compat.c |
| 10 | @@ -44,6 +44,7 @@ extern int protocol_version; |
| 11 | extern int protect_args; |
| 12 | extern int preserve_uid; |
| 13 | extern int preserve_gid; |
| 14 | +extern int preserve_atimes; |
| 15 | extern int preserve_acls; |
| 16 | extern int preserve_xattrs; |
| 17 | extern int need_messages_from_generator; |
| 18 | @@ -61,7 +62,7 @@ extern char *iconv_opt; |
| 19 | #endif |
| 20 | |
| 21 | /* These index values are for the file-list's extra-attribute array. */ |
| 22 | -int uid_ndx, gid_ndx, acls_ndx, xattrs_ndx, unsort_ndx; |
| 23 | +int uid_ndx, gid_ndx, atimes_ndx, acls_ndx, xattrs_ndx, unsort_ndx; |
| 24 | |
| 25 | int receiver_symlink_times = 0; /* receiver can set the time on a symlink */ |
| 26 | int sender_symlink_iconv = 0; /* sender should convert symlink content */ |
| 27 | @@ -137,6 +138,8 @@ void setup_protocol(int f_out,int f_in) |
| 28 | uid_ndx = ++file_extra_cnt; |
| 29 | if (preserve_gid) |
| 30 | gid_ndx = ++file_extra_cnt; |
| 31 | + if (preserve_atimes) |
| 32 | + atimes_ndx = (file_extra_cnt += TIME_EXTRA_CNT); |
| 33 | if (preserve_acls && !am_sender) |
| 34 | acls_ndx = ++file_extra_cnt; |
| 35 | if (preserve_xattrs) |
| 36 | diff --git a/flist.c b/flist.c |
| 37 | --- a/flist.c |
| 38 | +++ b/flist.c |
| 39 | @@ -55,6 +55,7 @@ extern int preserve_specials; |
| 40 | extern int uid_ndx; |
| 41 | extern int gid_ndx; |
| 42 | extern int eol_nulls; |
| 43 | +extern int atimes_ndx; |
| 44 | extern int relative_paths; |
| 45 | extern int implied_dirs; |
| 46 | extern int file_extra_cnt; |
| 47 | @@ -393,7 +394,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, |
| 48 | #endif |
| 49 | int ndx, int first_ndx) |
| 50 | { |
| 51 | - static time_t modtime; |
| 52 | + static time_t modtime, atime; |
| 53 | static mode_t mode; |
| 54 | #ifdef SUPPORT_HARD_LINKS |
| 55 | static int64 dev; |
| 56 | @@ -467,6 +468,13 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, |
| 57 | xflags |= XMIT_SAME_TIME; |
| 58 | else |
| 59 | modtime = file->modtime; |
| 60 | + if (atimes_ndx && !S_ISDIR(mode)) { |
| 61 | + time_t file_atime = f_atime(file); |
| 62 | + if (file_atime == atime) |
| 63 | + xflags |= XMIT_SAME_ATIME; |
| 64 | + else |
| 65 | + atime = file_atime; |
| 66 | + } |
| 67 | |
| 68 | #ifdef SUPPORT_HARD_LINKS |
| 69 | if (tmp_dev != 0) { |
| 70 | @@ -538,6 +546,8 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, |
| 71 | } |
| 72 | if (!(xflags & XMIT_SAME_MODE)) |
| 73 | write_int(f, to_wire_mode(mode)); |
| 74 | + if (atimes_ndx && !S_ISDIR(mode) && !(xflags & XMIT_SAME_ATIME)) |
| 75 | + write_varlong(f, atime, 4); |
| 76 | if (preserve_uid && !(xflags & XMIT_SAME_UID)) { |
| 77 | if (protocol_version < 30) |
| 78 | write_int(f, uid); |
| 79 | @@ -622,7 +632,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file, |
| 80 | static struct file_struct *recv_file_entry(struct file_list *flist, |
| 81 | int xflags, int f) |
| 82 | { |
| 83 | - static int64 modtime; |
| 84 | + static int64 modtime, atime; |
| 85 | static mode_t mode; |
| 86 | #ifdef SUPPORT_HARD_LINKS |
| 87 | static int64 dev; |
| 88 | @@ -756,6 +766,16 @@ static struct file_struct *recv_file_entry(struct file_list *flist, |
| 89 | } |
| 90 | if (!(xflags & XMIT_SAME_MODE)) |
| 91 | mode = from_wire_mode(read_int(f)); |
| 92 | + if (atimes_ndx && !S_ISDIR(mode) && !(xflags & XMIT_SAME_ATIME)) { |
| 93 | + atime = read_varlong(f, 4); |
| 94 | +#if SIZEOF_TIME_T < SIZEOF_INT64 |
| 95 | + if (!am_generator && (int64)(time_t)atime != atime) { |
| 96 | + rprintf(FERROR_XFER, |
| 97 | + "Access time value of %s truncated on receiver.\n", |
| 98 | + lastname); |
| 99 | + } |
| 100 | +#endif |
| 101 | + } |
| 102 | |
| 103 | if (chmod_modes && !S_ISLNK(mode)) |
| 104 | mode = tweak_mode(mode, chmod_modes); |
| 105 | @@ -905,6 +925,8 @@ static struct file_struct *recv_file_entry(struct file_list *flist, |
| 106 | F_GROUP(file) = gid; |
| 107 | file->flags |= gid_flags; |
| 108 | } |
| 109 | + if (atimes_ndx) |
| 110 | + f_atime_set(file, (time_t)atime); |
| 111 | if (unsort_ndx) |
| 112 | F_NDX(file) = flist->used + flist->ndx_start; |
| 113 | |
| 114 | @@ -1277,6 +1299,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist, |
| 115 | F_OWNER(file) = st.st_uid; |
| 116 | if (gid_ndx) /* Check gid_ndx instead of preserve_gid for del support */ |
| 117 | F_GROUP(file) = st.st_gid; |
| 118 | + if (atimes_ndx) |
| 119 | + f_atime_set(file, st.st_atime); |
| 120 | |
| 121 | if (basename != thisname) |
| 122 | file->dirname = lastdir; |
| 123 | diff --git a/generator.c b/generator.c |
| 124 | --- a/generator.c |
| 125 | +++ b/generator.c |
| 126 | @@ -21,6 +21,7 @@ |
| 127 | */ |
| 128 | |
| 129 | #include "rsync.h" |
| 130 | +#include "ifuncs.h" |
| 131 | |
| 132 | extern int verbose; |
| 133 | extern int dry_run; |
| 134 | @@ -645,6 +646,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre |
| 135 | : iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED) |
| 136 | && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) |
| 137 | iflags |= ITEM_REPORT_TIME; |
| 138 | + if (atimes_ndx && !S_ISDIR(file->mode) && !S_ISLNK(file->mode) |
| 139 | + && cmp_time(f_atime(file), sxp->st.st_atime) != 0) |
| 140 | + iflags |= ITEM_REPORT_ATIME; |
| 141 | #if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST |
| 142 | if (S_ISLNK(file->mode)) { |
| 143 | ; |
| 144 | @@ -1015,6 +1019,8 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx, |
| 145 | if (link_dest) { |
| 146 | if (!hard_link_one(file, fname, cmpbuf, 1)) |
| 147 | goto try_a_copy; |
| 148 | + if (atimes_ndx) |
| 149 | + set_file_attrs(fname, file, sxp, NULL, 0); |
| 150 | if (preserve_hard_links && F_IS_HLINKED(file)) |
| 151 | finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j); |
| 152 | if (!maybe_ATTRS_REPORT && (verbose > 1 || stdout_format_has_i > 1)) { |
| 153 | @@ -1200,6 +1206,7 @@ static int try_dests_non(struct file_struct *file, char *fname, int ndx, |
| 154 | static void list_file_entry(struct file_struct *f) |
| 155 | { |
| 156 | char permbuf[PERMSTRING_SIZE]; |
| 157 | + time_t atime = atimes_ndx ? f_atime(f) : 0; |
| 158 | double len; |
| 159 | |
| 160 | if (!F_IS_ACTIVE(f)) { |
| 161 | @@ -1214,14 +1221,16 @@ static void list_file_entry(struct file_struct *f) |
| 162 | |
| 163 | #ifdef SUPPORT_LINKS |
| 164 | if (preserve_links && S_ISLNK(f->mode)) { |
| 165 | - rprintf(FINFO, "%s %11.0f %s %s -> %s\n", |
| 166 | + rprintf(FINFO, "%s %11.0f %s %s %s -> %s\n", |
| 167 | permbuf, len, timestring(f->modtime), |
| 168 | + atimes_ndx ? timestring(atime) : "", |
| 169 | f_name(f, NULL), F_SYMLINK(f)); |
| 170 | } else |
| 171 | #endif |
| 172 | { |
| 173 | - rprintf(FINFO, "%s %11.0f %s %s\n", |
| 174 | + rprintf(FINFO, "%s %11.0f %s %s %s\n", |
| 175 | permbuf, len, timestring(f->modtime), |
| 176 | + atimes_ndx ? timestring(atime) : "", |
| 177 | f_name(f, NULL)); |
| 178 | } |
| 179 | } |
| 180 | @@ -2056,7 +2065,7 @@ static void touch_up_dirs(struct file_list *flist, int ndx) |
| 181 | STRUCT_STAT st; |
| 182 | if (link_stat(fname, &st, 0) == 0 |
| 183 | && cmp_time(st.st_mtime, file->modtime) != 0) |
| 184 | - set_modtime(fname, file->modtime, file->mode); |
| 185 | + set_times(fname, file->modtime, file->modtime, file->mode); |
| 186 | } |
| 187 | if (counter >= loopchk_limit) { |
| 188 | if (allowed_lull) |
| 189 | diff --git a/ifuncs.h b/ifuncs.h |
| 190 | --- a/ifuncs.h |
| 191 | +++ b/ifuncs.h |
| 192 | @@ -67,6 +67,28 @@ d_name(struct dirent *di) |
| 193 | #endif |
| 194 | } |
| 195 | |
| 196 | +static inline time_t |
| 197 | +f_atime(struct file_struct *fp) |
| 198 | +{ |
| 199 | +#if SIZEOF_TIME_T > 4 |
| 200 | + time_t atime; |
| 201 | + memcpy(&atime, &REQ_EXTRA(fp, atimes_ndx)->unum, SIZEOF_TIME_T); |
| 202 | + return atime; |
| 203 | +#else |
| 204 | + return REQ_EXTRA(fp, atimes_ndx)->unum; |
| 205 | +#endif |
| 206 | +} |
| 207 | + |
| 208 | +static inline void |
| 209 | +f_atime_set(struct file_struct *fp, time_t atime) |
| 210 | +{ |
| 211 | +#if SIZEOF_TIME_T > 4 |
| 212 | + memcpy(&REQ_EXTRA(fp, atimes_ndx)->unum, &atime, SIZEOF_TIME_T); |
| 213 | +#else |
| 214 | + REQ_EXTRA(fp, atimes_ndx)->unum = (uint32)atime; |
| 215 | +#endif |
| 216 | +} |
| 217 | + |
| 218 | static inline int |
| 219 | isDigit(const char *ptr) |
| 220 | { |
| 221 | diff --git a/log.c b/log.c |
| 222 | --- a/log.c |
| 223 | +++ b/log.c |
| 224 | @@ -660,7 +660,8 @@ static void log_formatted(enum logcode code, const char *format, const char *op, |
| 225 | c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p'; |
| 226 | c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o'; |
| 227 | c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g'; |
| 228 | - c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u'; |
| 229 | + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' |
| 230 | + : S_ISLNK(file->mode) ? 'U' : 'u'; |
| 231 | c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a'; |
| 232 | c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x'; |
| 233 | c[11] = '\0'; |
| 234 | diff --git a/options.c b/options.c |
| 235 | --- a/options.c |
| 236 | +++ b/options.c |
| 237 | @@ -59,6 +59,7 @@ int preserve_specials = 0; |
| 238 | int preserve_uid = 0; |
| 239 | int preserve_gid = 0; |
| 240 | int preserve_times = 0; |
| 241 | +int preserve_atimes = 0; |
| 242 | int update_only = 0; |
| 243 | int cvs_exclude = 0; |
| 244 | int dry_run = 0; |
| 245 | @@ -353,6 +354,7 @@ void usage(enum logcode F) |
| 246 | rprintf(F," -D same as --devices --specials\n"); |
| 247 | rprintf(F," -t, --times preserve modification times\n"); |
| 248 | rprintf(F," -O, --omit-dir-times omit directories from --times\n"); |
| 249 | + rprintf(F," -U, --atimes preserve access (last-used) times\n"); |
| 250 | rprintf(F," --super receiver attempts super-user activities\n"); |
| 251 | #ifdef SUPPORT_XATTRS |
| 252 | rprintf(F," --fake-super store/recover privileged attrs using xattrs\n"); |
| 253 | @@ -490,6 +492,9 @@ static struct poptOption long_options[] = { |
| 254 | {"times", 't', POPT_ARG_VAL, &preserve_times, 2, 0, 0 }, |
| 255 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, |
| 256 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, |
| 257 | + {"atimes", 'U', POPT_ARG_VAL, &preserve_atimes, 1, 0, 0 }, |
| 258 | + {"no-atimes", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 }, |
| 259 | + {"no-U", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 }, |
| 260 | {"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 }, |
| 261 | {"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 }, |
| 262 | {"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 }, |
| 263 | @@ -1773,6 +1778,8 @@ void server_options(char **args, int *argc_p) |
| 264 | argstr[x++] = 'D'; |
| 265 | if (preserve_times) |
| 266 | argstr[x++] = 't'; |
| 267 | + if (preserve_atimes) |
| 268 | + argstr[x++] = 'U'; |
| 269 | if (preserve_perms) |
| 270 | argstr[x++] = 'p'; |
| 271 | else if (preserve_executability && am_sender) |
| 272 | diff --git a/rsync.c b/rsync.c |
| 273 | --- a/rsync.c |
| 274 | +++ b/rsync.c |
| 275 | @@ -380,6 +380,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, |
| 276 | int updated = 0; |
| 277 | stat_x sx2; |
| 278 | int change_uid, change_gid; |
| 279 | + time_t atime, mtime; |
| 280 | mode_t new_mode = file->mode; |
| 281 | int inherit; |
| 282 | |
| 283 | @@ -423,20 +424,38 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp, |
| 284 | set_xattr(fname, file, fnamecmp, sxp); |
| 285 | #endif |
| 286 | |
| 287 | + /* This code must be the first update in the function due to |
| 288 | + * how it uses the "updated" variable. */ |
| 289 | if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && preserve_times == 1)) |
| 290 | flags |= ATTRS_SKIP_MTIME; |
| 291 | + if (!atimes_ndx || S_ISDIR(sxp->st.st_mode)) |
| 292 | + flags |= ATTRS_SKIP_ATIME; |
| 293 | if (!(flags & ATTRS_SKIP_MTIME) |
| 294 | && cmp_time(sxp->st.st_mtime, file->modtime) != 0) { |
| 295 | - int ret = set_modtime(fname, file->modtime, sxp->st.st_mode); |
| 296 | + mtime = file->modtime; |
| 297 | + updated = 1; |
| 298 | + } else |
| 299 | + mtime = sxp->st.st_mtime; |
| 300 | + if (!(flags & ATTRS_SKIP_ATIME)) { |
| 301 | + time_t file_atime = f_atime(file); |
| 302 | + if (cmp_time(sxp->st.st_atime, file_atime) != 0) { |
| 303 | + atime = file_atime; |
| 304 | + updated = 1; |
| 305 | + } else |
| 306 | + atime = sxp->st.st_atime; |
| 307 | + } else |
| 308 | + atime = sxp->st.st_atime; |
| 309 | + if (updated) { |
| 310 | + int ret = set_times(fname, mtime, atime, sxp->st.st_mode); |
| 311 | if (ret < 0) { |
| 312 | rsyserr(FERROR_XFER, errno, "failed to set times on %s", |
| 313 | full_fname(fname)); |
| 314 | goto cleanup; |
| 315 | } |
| 316 | - if (ret == 0) /* ret == 1 if symlink could not be set */ |
| 317 | - updated = 1; |
| 318 | - else |
| 319 | + if (ret > 0) { /* ret == 1 if symlink could not be set */ |
| 320 | + updated = 0; |
| 321 | file->flags |= FLAG_TIME_FAILED; |
| 322 | + } |
| 323 | } |
| 324 | |
| 325 | change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file); |
| 326 | @@ -570,7 +589,7 @@ int finish_transfer(const char *fname, const char *fnametmp, |
| 327 | |
| 328 | /* Change permissions before putting the file into place. */ |
| 329 | set_file_attrs(fnametmp, file, NULL, fnamecmp, |
| 330 | - ok_to_set_time ? 0 : ATTRS_SKIP_MTIME); |
| 331 | + ok_to_set_time ? 0 : ATTRS_SKIP_MTIME | ATTRS_SKIP_ATIME); |
| 332 | |
| 333 | /* move tmp file over real file */ |
| 334 | if (verbose > 2) |
| 335 | @@ -597,7 +616,7 @@ int finish_transfer(const char *fname, const char *fnametmp, |
| 336 | |
| 337 | do_set_file_attrs: |
| 338 | set_file_attrs(fnametmp, file, NULL, fnamecmp, |
| 339 | - ok_to_set_time ? 0 : ATTRS_SKIP_MTIME); |
| 340 | + ok_to_set_time ? 0 : ATTRS_SKIP_MTIME | ATTRS_SKIP_ATIME); |
| 341 | |
| 342 | if (temp_copy_name) { |
| 343 | if (do_rename(fnametmp, fname) < 0) { |
| 344 | diff --git a/rsync.h b/rsync.h |
| 345 | --- a/rsync.h |
| 346 | +++ b/rsync.h |
| 347 | @@ -60,6 +60,7 @@ |
| 348 | #define XMIT_RDEV_MINOR_8_pre30 (1<<11) /* protocols 28 - 29 */ |
| 349 | #define XMIT_GROUP_NAME_FOLLOWS (1<<11) /* protocols 30 - now */ |
| 350 | #define XMIT_HLINK_FIRST (1<<12) /* protocols 30 - now (HLINKED files only) */ |
| 351 | +#define XMIT_SAME_ATIME (1<<13) /* protocols ?? - now */ |
| 352 | |
| 353 | /* These flags are used in the live flist data. */ |
| 354 | |
| 355 | @@ -154,6 +155,7 @@ |
| 356 | |
| 357 | #define ATTRS_REPORT (1<<0) |
| 358 | #define ATTRS_SKIP_MTIME (1<<1) |
| 359 | +#define ATTRS_SKIP_ATIME (1<<2) |
| 360 | |
| 361 | #define FULL_FLUSH 1 |
| 362 | #define NORMAL_FLUSH 0 |
| 363 | @@ -632,12 +634,14 @@ extern int file_extra_cnt; |
| 364 | extern int inc_recurse; |
| 365 | extern int uid_ndx; |
| 366 | extern int gid_ndx; |
| 367 | +extern int atimes_ndx; |
| 368 | extern int acls_ndx; |
| 369 | extern int xattrs_ndx; |
| 370 | |
| 371 | #define FILE_STRUCT_LEN (offsetof(struct file_struct, basename)) |
| 372 | #define EXTRA_LEN (sizeof (union file_extras)) |
| 373 | #define PTR_EXTRA_CNT ((sizeof (char *) + EXTRA_LEN - 1) / EXTRA_LEN) |
| 374 | +#define TIME_EXTRA_CNT ((SIZEOF_TIME_T + EXTRA_LEN - 1) / EXTRA_LEN) |
| 375 | #define DEV_EXTRA_CNT 2 |
| 376 | #define DIRNODE_EXTRA_CNT 3 |
| 377 | #define SUM_EXTRA_CNT ((MAX_DIGEST_LEN + EXTRA_LEN - 1) / EXTRA_LEN) |
| 378 | diff --git a/rsync.yo b/rsync.yo |
| 379 | --- a/rsync.yo |
| 380 | +++ b/rsync.yo |
| 381 | @@ -349,6 +349,7 @@ to the detailed description below for a complete description. verb( |
| 382 | -D same as --devices --specials |
| 383 | -t, --times preserve modification times |
| 384 | -O, --omit-dir-times omit directories from --times |
| 385 | + -U, --atimes preserve access (use) times |
| 386 | --super receiver attempts super-user activities |
| 387 | --fake-super store/recover privileged attrs using xattrs |
| 388 | -S, --sparse handle sparse files efficiently |
| 389 | @@ -1000,6 +1001,12 @@ it is preserving modification times (see bf(--times)). If NFS is sharing |
| 390 | the directories on the receiving side, it is a good idea to use bf(-O). |
| 391 | This option is inferred if you use bf(--backup) without bf(--backup-dir). |
| 392 | |
| 393 | +dit(bf(-U, --atimes)) This tells rsync to set the access (use) times of the |
| 394 | +destination files to the same value as the source files. Note that the |
| 395 | +reading of the source file may update the atime of the source files, so |
| 396 | +repeated rsync runs with --atimes may be needed if you want to force the |
| 397 | +access-time values to be 100% identical on the two systems. |
| 398 | + |
| 399 | dit(bf(--super)) This tells the receiving side to attempt super-user |
| 400 | activities even if the receiving rsync wasn't run by the super-user. These |
| 401 | activities include: preserving users via the bf(--owner) option, preserving |
| 402 | @@ -1719,7 +1726,10 @@ quote(itemization( |
| 403 | sender's value (requires bf(--owner) and super-user privileges). |
| 404 | it() A bf(g) means the group is different and is being updated to the |
| 405 | sender's value (requires bf(--group) and the authority to set the group). |
| 406 | - it() The bf(u) slot is reserved for future use. |
| 407 | + it() A bf(u) means the access (use) time is different and is being updated to |
| 408 | + the sender's value (requires bf(--atimes)). An alternate value of bf(U) |
| 409 | + means that the access time will be set to the transfer time, which happens |
| 410 | + when a symlink or directory is updated. |
| 411 | it() The bf(a) means that the ACL information changed. |
| 412 | it() The bf(x) means that the extended attribute information changed. |
| 413 | )) |
| 414 | diff --git a/testsuite/atimes.test b/testsuite/atimes.test |
| 415 | new file mode 100644 |
| 416 | --- /dev/null |
| 417 | +++ b/testsuite/atimes.test |
| 418 | @@ -0,0 +1,17 @@ |
| 419 | +#! /bin/sh |
| 420 | + |
| 421 | +# Test rsync copying atimes |
| 422 | + |
| 423 | +. "$suitedir/rsync.fns" |
| 424 | + |
| 425 | +mkdir "$fromdir" |
| 426 | + |
| 427 | +touch "$fromdir/foo" |
| 428 | +touch -a -t 200102031717.42 "$fromdir/foo" |
| 429 | + |
| 430 | +TLS_ARGS=--atimes |
| 431 | + |
| 432 | +checkit "$RSYNC -rtUgvvv \"$fromdir/\" \"$todir/\"" "$fromdir" "$todir" |
| 433 | + |
| 434 | +# The script would have aborted on error, so getting here means we've won. |
| 435 | +exit 0 |
| 436 | diff --git a/testsuite/rsync.fns b/testsuite/rsync.fns |
| 437 | --- a/testsuite/rsync.fns |
| 438 | +++ b/testsuite/rsync.fns |
| 439 | @@ -215,6 +215,10 @@ checkit() { |
| 440 | # We can just write everything to stdout/stderr, because the |
| 441 | # wrapper hides it unless there is a problem. |
| 442 | |
| 443 | + if test x$TLS_ARGS = x--atimes; then |
| 444 | + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from" |
| 445 | + fi |
| 446 | + |
| 447 | echo "Running: \"$1\"" |
| 448 | eval "$1" |
| 449 | status=$? |
| 450 | @@ -222,10 +226,13 @@ checkit() { |
| 451 | failed="YES"; |
| 452 | fi |
| 453 | |
| 454 | + if test x$TLS_ARGS != x--atimes; then |
| 455 | + ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from" |
| 456 | + fi |
| 457 | + |
| 458 | echo "-------------" |
| 459 | echo "check how the directory listings compare with diff:" |
| 460 | echo "" |
| 461 | - ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from" |
| 462 | ( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to" |
| 463 | diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES |
| 464 | |
| 465 | diff --git a/tls.c b/tls.c |
| 466 | --- a/tls.c |
| 467 | +++ b/tls.c |
| 468 | @@ -107,6 +107,8 @@ static int stat_xattr(const char *fname, STRUCT_STAT *fst) |
| 469 | |
| 470 | #endif |
| 471 | |
| 472 | +static int display_atimes = 0; |
| 473 | + |
| 474 | static void failed(char const *what, char const *where) |
| 475 | { |
| 476 | fprintf(stderr, PROGRAM ": %s %s: %s\n", |
| 477 | @@ -114,12 +116,29 @@ static void failed(char const *what, char const *where) |
| 478 | exit(1); |
| 479 | } |
| 480 | |
| 481 | +static void storetime(char *dest, time_t t, size_t destsize) |
| 482 | +{ |
| 483 | + if (t) { |
| 484 | + struct tm *mt = gmtime(&t); |
| 485 | + |
| 486 | + snprintf(dest, destsize, |
| 487 | + "%04d-%02d-%02d %02d:%02d:%02d ", |
| 488 | + (int)mt->tm_year + 1900, |
| 489 | + (int)mt->tm_mon + 1, |
| 490 | + (int)mt->tm_mday, |
| 491 | + (int)mt->tm_hour, |
| 492 | + (int)mt->tm_min, |
| 493 | + (int)mt->tm_sec); |
| 494 | + } else |
| 495 | + strlcpy(dest, " ", destsize); |
| 496 | +} |
| 497 | + |
| 498 | static void list_file(const char *fname) |
| 499 | { |
| 500 | STRUCT_STAT buf; |
| 501 | char permbuf[PERMSTRING_SIZE]; |
| 502 | - struct tm *mt; |
| 503 | - char datebuf[50]; |
| 504 | + char mtimebuf[50]; |
| 505 | + char atimebuf[50]; |
| 506 | char linkbuf[4096]; |
| 507 | |
| 508 | if (do_lstat(fname, &buf) < 0) |
| 509 | @@ -158,19 +177,11 @@ static void list_file(const char *fname) |
| 510 | |
| 511 | permstring(permbuf, buf.st_mode); |
| 512 | |
| 513 | - if (buf.st_mtime) { |
| 514 | - mt = gmtime(&buf.st_mtime); |
| 515 | - |
| 516 | - snprintf(datebuf, sizeof datebuf, |
| 517 | - "%04d-%02d-%02d %02d:%02d:%02d", |
| 518 | - (int)mt->tm_year + 1900, |
| 519 | - (int)mt->tm_mon + 1, |
| 520 | - (int)mt->tm_mday, |
| 521 | - (int)mt->tm_hour, |
| 522 | - (int)mt->tm_min, |
| 523 | - (int)mt->tm_sec); |
| 524 | - } else |
| 525 | - strlcpy(datebuf, " ", sizeof datebuf); |
| 526 | + storetime(mtimebuf, buf.st_mtime, sizeof mtimebuf); |
| 527 | + if (display_atimes) |
| 528 | + storetime(atimebuf, S_ISDIR(buf.st_mode) ? 0 : buf.st_atime, sizeof atimebuf); |
| 529 | + else |
| 530 | + atimebuf[0] = '\0'; |
| 531 | |
| 532 | /* TODO: Perhaps escape special characters in fname? */ |
| 533 | |
| 534 | @@ -181,13 +192,14 @@ static void list_file(const char *fname) |
| 535 | (long)minor(buf.st_rdev)); |
| 536 | } else /* NB: use double for size since it might not fit in a long. */ |
| 537 | printf("%12.0f", (double)buf.st_size); |
| 538 | - printf(" %6ld.%-6ld %6ld %s %s%s\n", |
| 539 | + printf(" %6ld.%-6ld %6ld %s%s%s%s\n", |
| 540 | (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink, |
| 541 | - datebuf, fname, linkbuf); |
| 542 | + mtimebuf, atimebuf, fname, linkbuf); |
| 543 | } |
| 544 | |
| 545 | static struct poptOption long_options[] = { |
| 546 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ |
| 547 | + {"atimes", 'U', POPT_ARG_NONE, &display_atimes, 0, 0, 0}, |
| 548 | {"link-times", 'l', POPT_ARG_NONE, &link_times, 0, 0, 0 }, |
| 549 | {"link-owner", 'L', POPT_ARG_NONE, &link_owner, 0, 0, 0 }, |
| 550 | #ifdef SUPPORT_XATTRS |
| 551 | @@ -203,6 +215,7 @@ static void tls_usage(int ret) |
| 552 | fprintf(F,"usage: " PROGRAM " [OPTIONS] FILE ...\n"); |
| 553 | fprintf(F,"Trivial file listing program for portably checking rsync\n"); |
| 554 | fprintf(F,"\nOptions:\n"); |
| 555 | + fprintf(F," -U, --atimes display access (last-used) times\n"); |
| 556 | fprintf(F," -l, --link-times display the time on a symlink\n"); |
| 557 | fprintf(F," -L, --link-owner display the owner+group on a symlink\n"); |
| 558 | #ifdef SUPPORT_XATTRS |
| 559 | diff --git a/util.c b/util.c |
| 560 | --- a/util.c |
| 561 | +++ b/util.c |
| 562 | @@ -123,7 +123,7 @@ NORETURN void overflow_exit(const char *str) |
| 563 | exit_cleanup(RERR_MALLOC); |
| 564 | } |
| 565 | |
| 566 | -int set_modtime(const char *fname, time_t modtime, mode_t mode) |
| 567 | +int set_times(const char *fname, time_t modtime, time_t atime, mode_t mode) |
| 568 | { |
| 569 | #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES |
| 570 | if (S_ISLNK(mode)) |
| 571 | @@ -131,9 +131,13 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode) |
| 572 | #endif |
| 573 | |
| 574 | if (verbose > 2) { |
| 575 | - rprintf(FINFO, "set modtime of %s to (%ld) %s", |
| 576 | + char mtimebuf[200]; |
| 577 | + |
| 578 | + strlcpy(mtimebuf, timestring(modtime), sizeof mtimebuf); |
| 579 | + rprintf(FINFO, |
| 580 | + "set modtime, atime of %s to (%ld) %s, (%ld) %s\n", |
| 581 | fname, (long)modtime, |
| 582 | - asctime(localtime(&modtime))); |
| 583 | + mtimebuf, (long)atime, timestring(atime)); |
| 584 | } |
| 585 | |
| 586 | if (dry_run) |
| 587 | @@ -142,7 +146,7 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode) |
| 588 | { |
| 589 | #ifdef HAVE_UTIMES |
| 590 | struct timeval t[2]; |
| 591 | - t[0].tv_sec = time(NULL); |
| 592 | + t[0].tv_sec = atime; |
| 593 | t[0].tv_usec = 0; |
| 594 | t[1].tv_sec = modtime; |
| 595 | t[1].tv_usec = 0; |
| 596 | @@ -156,12 +160,12 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode) |
| 597 | return utimes(fname, t); |
| 598 | #elif defined HAVE_STRUCT_UTIMBUF |
| 599 | struct utimbuf tbuf; |
| 600 | - tbuf.actime = time(NULL); |
| 601 | + tbuf.actime = atime; |
| 602 | tbuf.modtime = modtime; |
| 603 | return utime(fname,&tbuf); |
| 604 | #elif defined HAVE_UTIME |
| 605 | time_t t[2]; |
| 606 | - t[0] = time(NULL); |
| 607 | + t[0] = atime; |
| 608 | t[1] = modtime; |
| 609 | return utime(fname,t); |
| 610 | #else |