./configure (optional if already run)
make
-based-on: 2f01fb11526f4a8fed3e5e6189706845c04136f3
+based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
diff --git a/compat.c b/compat.c
--- a/compat.c
+++ b/compat.c
-@@ -45,6 +45,7 @@ extern int protocol_version;
+@@ -46,6 +46,7 @@ extern int protocol_version;
extern int protect_args;
extern int preserve_uid;
extern int preserve_gid;
extern int preserve_acls;
extern int preserve_xattrs;
extern int need_messages_from_generator;
-@@ -62,7 +63,7 @@ extern char *iconv_opt;
+@@ -63,7 +64,7 @@ extern char *iconv_opt;
#endif
/* These index values are for the file-list's extra-attribute array. */
int receiver_symlink_times = 0; /* receiver can set the time on a symlink */
int sender_symlink_iconv = 0; /* sender should convert symlink content */
-@@ -139,6 +140,8 @@ void setup_protocol(int f_out,int f_in)
+@@ -140,6 +141,8 @@ void setup_protocol(int f_out,int f_in)
uid_ndx = ++file_extra_cnt;
if (preserve_gid)
gid_ndx = ++file_extra_cnt;
diff --git a/flist.c b/flist.c
--- a/flist.c
+++ b/flist.c
-@@ -55,6 +55,7 @@ extern int delete_during;
- extern int uid_ndx;
- extern int gid_ndx;
+@@ -53,6 +53,7 @@ extern int preserve_devices;
+ extern int preserve_specials;
+ extern int delete_during;
extern int eol_nulls;
+extern int atimes_ndx;
extern int relative_paths;
extern int implied_dirs;
- extern int file_extra_cnt;
-@@ -394,7 +395,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
+ extern int ignore_perishable;
+@@ -392,7 +393,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
#endif
int ndx, int first_ndx)
{
static mode_t mode;
#ifdef SUPPORT_HARD_LINKS
static int64 dev;
-@@ -478,6 +479,13 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
+@@ -476,6 +477,13 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
xflags |= XMIT_SAME_TIME;
else
modtime = file->modtime;
+ }
#ifdef SUPPORT_HARD_LINKS
- if (tmp_dev != 0) {
-@@ -549,6 +557,8 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
+ if (tmp_dev != -1) {
+@@ -547,6 +555,8 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
}
if (!(xflags & XMIT_SAME_MODE))
write_int(f, to_wire_mode(mode));
if (preserve_uid && !(xflags & XMIT_SAME_UID)) {
if (protocol_version < 30)
write_int(f, uid);
-@@ -633,7 +643,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
- static struct file_struct *recv_file_entry(struct file_list *flist,
- int xflags, int f)
+@@ -632,7 +642,7 @@ static void send_file_entry(int f, const char *fname, struct file_struct *file,
+
+ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int xflags)
{
- static int64 modtime;
+ static int64 modtime, atime;
static mode_t mode;
#ifdef SUPPORT_HARD_LINKS
static int64 dev;
-@@ -766,6 +776,16 @@ static struct file_struct *recv_file_entry(struct file_list *flist,
+@@ -765,6 +775,16 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
}
if (!(xflags & XMIT_SAME_MODE))
mode = from_wire_mode(read_int(f));
if (chmod_modes && !S_ISLNK(mode))
mode = tweak_mode(mode, chmod_modes);
-@@ -916,6 +936,8 @@ static struct file_struct *recv_file_entry(struct file_list *flist,
+@@ -915,6 +935,8 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
F_GROUP(file) = gid;
file->flags |= gid_flags;
}
if (unsort_ndx)
F_NDX(file) = flist->used + flist->ndx_start;
-@@ -1288,6 +1310,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
- F_OWNER(file) = st.st_uid;
- if (gid_ndx) /* Check gid_ndx instead of preserve_gid for del support */
+@@ -1289,6 +1311,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
F_GROUP(file) = st.st_gid;
+ if (am_generator && st.st_uid == our_uid)
+ file->flags |= FLAG_OWNED_BY_US;
+ if (atimes_ndx)
+ f_atime_set(file, st.st_atime);
extern int verbose;
extern int dry_run;
-@@ -648,6 +649,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
+@@ -682,6 +683,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
: iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED)
&& (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
iflags |= ITEM_REPORT_TIME;
#if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST
if (S_ISLNK(file->mode)) {
;
-@@ -1018,6 +1022,8 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
+@@ -1058,6 +1062,8 @@ static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
if (link_dest) {
if (!hard_link_one(file, fname, cmpbuf, 1))
goto try_a_copy;
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j);
if (!maybe_ATTRS_REPORT && (verbose > 1 || stdout_format_has_i > 1)) {
-@@ -1203,6 +1209,7 @@ static int try_dests_non(struct file_struct *file, char *fname, int ndx,
+@@ -1243,6 +1249,7 @@ static int try_dests_non(struct file_struct *file, char *fname, int ndx,
static void list_file_entry(struct file_struct *f)
{
char permbuf[PERMSTRING_SIZE];
double len;
if (!F_IS_ACTIVE(f)) {
-@@ -1217,14 +1224,16 @@ static void list_file_entry(struct file_struct *f)
+@@ -1257,14 +1264,16 @@ static void list_file_entry(struct file_struct *f)
#ifdef SUPPORT_LINKS
if (preserve_links && S_ISLNK(f->mode)) {
f_name(f, NULL));
}
}
-@@ -2066,7 +2075,7 @@ static void touch_up_dirs(struct file_list *flist, int ndx)
+@@ -2121,7 +2130,7 @@ static void touch_up_dirs(struct file_list *flist, int ndx)
STRUCT_STAT st;
if (link_stat(fname, &st, 0) == 0
&& cmp_time(st.st_mtime, file->modtime) != 0)
diff --git a/log.c b/log.c
--- a/log.c
+++ b/log.c
-@@ -660,7 +660,8 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
+@@ -658,7 +658,8 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
int update_only = 0;
int cvs_exclude = 0;
int dry_run = 0;
-@@ -353,6 +354,7 @@ void usage(enum logcode F)
+@@ -352,6 +353,7 @@ void usage(enum logcode F)
rprintf(F," -D same as --devices --specials\n");
rprintf(F," -t, --times preserve modification times\n");
rprintf(F," -O, --omit-dir-times omit directories from --times\n");
rprintf(F," --super receiver attempts super-user activities\n");
#ifdef SUPPORT_XATTRS
rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
-@@ -490,6 +492,9 @@ static struct poptOption long_options[] = {
- {"times", 't', POPT_ARG_VAL, &preserve_times, 2, 0, 0 },
+@@ -489,6 +491,9 @@ static struct poptOption long_options[] = {
+ {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
{"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
+ {"atimes", 'U', POPT_ARG_VAL, &preserve_atimes, 1, 0, 0 },
{"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 },
{"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
{"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
-@@ -1779,6 +1784,8 @@ void server_options(char **args, int *argc_p)
+@@ -1784,6 +1789,8 @@ void server_options(char **args, int *argc_p)
argstr[x++] = 'D';
if (preserve_times)
argstr[x++] = 't';
diff --git a/rsync.c b/rsync.c
--- a/rsync.c
+++ b/rsync.c
-@@ -382,6 +382,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
+@@ -380,6 +380,7 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
int updated = 0;
stat_x sx2;
int change_uid, change_gid;
mode_t new_mode = file->mode;
int inherit;
-@@ -425,20 +426,38 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
+@@ -423,22 +424,40 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
set_xattr(fname, file, fnamecmp, sxp);
#endif
+ /* This code must be the first update in the function due to
+ * how it uses the "updated" variable. */
- if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && preserve_times == 1))
+ if (!preserve_times
+ || (!(preserve_times & PRESERVE_DIR_TIMES) && S_ISDIR(sxp->st.st_mode))
+ || (!(preserve_times & PRESERVE_LINK_TIMES) && S_ISLNK(sxp->st.st_mode)))
flags |= ATTRS_SKIP_MTIME;
+ if (!atimes_ndx || S_ISDIR(sxp->st.st_mode))
+ flags |= ATTRS_SKIP_ATIME;
}
change_uid = am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file);
-@@ -572,7 +591,7 @@ int finish_transfer(const char *fname, const char *fnametmp,
+@@ -578,7 +597,7 @@ int finish_transfer(const char *fname, const char *fnametmp,
/* Change permissions before putting the file into place. */
set_file_attrs(fnametmp, file, NULL, fnamecmp,
/* move tmp file over real file */
if (verbose > 2)
-@@ -599,7 +618,7 @@ int finish_transfer(const char *fname, const char *fnametmp,
+@@ -605,7 +624,7 @@ int finish_transfer(const char *fname, const char *fnametmp,
do_set_file_attrs:
set_file_attrs(fnametmp, file, NULL, fnamecmp,
/* These flags are used in the live flist data. */
-@@ -155,6 +156,7 @@
+@@ -160,6 +161,7 @@
#define ATTRS_REPORT (1<<0)
#define ATTRS_SKIP_MTIME (1<<1)
#define FULL_FLUSH 1
#define NORMAL_FLUSH 0
-@@ -633,12 +635,14 @@ extern int file_extra_cnt;
+@@ -652,12 +654,14 @@ extern int file_extra_cnt;
extern int inc_recurse;
extern int uid_ndx;
extern int gid_ndx;
diff --git a/rsync.yo b/rsync.yo
--- a/rsync.yo
+++ b/rsync.yo
-@@ -353,6 +353,7 @@ to the detailed description below for a complete description. verb(
+@@ -366,6 +366,7 @@ to the detailed description below for a complete description. verb(
-D same as --devices --specials
-t, --times preserve modification times
-O, --omit-dir-times omit directories from --times
--super receiver attempts super-user activities
--fake-super store/recover privileged attrs using xattrs
-S, --sparse handle sparse files efficiently
-@@ -1011,6 +1012,12 @@ it is preserving modification times (see bf(--times)). If NFS is sharing
+@@ -1077,6 +1078,12 @@ it is preserving modification times (see bf(--times)). If NFS is sharing
the directories on the receiving side, it is a good idea to use bf(-O).
This option is inferred if you use bf(--backup) without bf(--backup-dir).
dit(bf(--super)) This tells the receiving side to attempt super-user
activities even if the receiving rsync wasn't run by the super-user. These
activities include: preserving users via the bf(--owner) option, preserving
-@@ -1744,7 +1751,10 @@ quote(itemization(
+@@ -1838,7 +1845,10 @@ quote(itemization(
sender's value (requires bf(--owner) and super-user privileges).
it() A bf(g) means the group is different and is being updated to the
sender's value (requires bf(--group) and the authority to set the group).
it() The bf(a) means that the ACL information changed.
it() The bf(x) means that the extended attribute information changed.
))
+diff --git a/syscall.c b/syscall.c
+--- a/syscall.c
++++ b/syscall.c
+@@ -302,15 +302,15 @@ OFF_T do_lseek(int fd, OFF_T offset, int whence)
+ }
+
+ #ifdef HAVE_UTIMENSAT
+-int do_utimensat(const char *fname, time_t modtime, uint32 mod_nsec)
++int do_utimensat(const char *fname, time_t modtime, uint32 mod_nsec, time_t atime, uint32 a_nsec)
+ {
+ struct timespec t[2];
+
+ if (dry_run) return 0;
+ RETURN_ERROR_IF_RO_OR_LO;
+
+- t[0].tv_sec = 0;
+- t[0].tv_nsec = UTIME_NOW;
++ t[0].tv_sec = atime;
++ t[0].tv_nsec = a_nsec;
+ t[1].tv_sec = modtime;
+ t[1].tv_nsec = mod_nsec;
+ return utimensat(AT_FDCWD, fname, t, AT_SYMLINK_NOFOLLOW);
+@@ -318,15 +318,15 @@ int do_utimensat(const char *fname, time_t modtime, uint32 mod_nsec)
+ #endif
+
+ #ifdef HAVE_LUTIMES
+-int do_lutimes(const char *fname, time_t modtime, uint32 mod_nsec)
++int do_lutimes(const char *fname, time_t modtime, uint32 mod_nsec, time_t atime, uint32 a_nsec)
+ {
+ struct timeval t[2];
+
+ if (dry_run) return 0;
+ RETURN_ERROR_IF_RO_OR_LO;
+
+- t[0].tv_sec = time(NULL);
+- t[0].tv_usec = 0;
++ t[0].tv_sec = atime;
++ t[0].tv_usec = a_nsec;
+ t[1].tv_sec = modtime;
+ t[1].tv_usec = mod_nsec / 1000;
+ return lutimes(fname, t);
+@@ -334,22 +334,22 @@ int do_lutimes(const char *fname, time_t modtime, uint32 mod_nsec)
+ #endif
+
+ #ifdef HAVE_UTIMES
+-int do_utimes(const char *fname, time_t modtime, uint32 mod_nsec)
++int do_utimes(const char *fname, time_t modtime, uint32 mod_nsec, time_t atime, uint32 a_nsec)
+ {
+ struct timeval t[2];
+
+ if (dry_run) return 0;
+ RETURN_ERROR_IF_RO_OR_LO;
+
+- t[0].tv_sec = time(NULL);
+- t[0].tv_usec = 0;
++ t[0].tv_sec = atime;
++ t[0].tv_usec = a_nsec;
+ t[1].tv_sec = modtime;
+ t[1].tv_usec = mod_nsec / 1000;
+ return utimes(fname, t);
+ }
+
+ #elif defined HAVE_UTIME
+-int do_utime(const char *fname, time_t modtime, UNUSED(uint32 mod_nsec))
++int do_utime(const char *fname, time_t modtime, UNUSED(uint32 mod_nsec), time_t atime, UNUSED(uint32 a_nsec))
+ {
+ #ifdef HAVE_STRUCT_UTIMBUF
+ struct utimbuf tbuf;
+@@ -361,11 +361,11 @@ int do_utime(const char *fname, time_t modtime, UNUSED(uint32 mod_nsec))
+ RETURN_ERROR_IF_RO_OR_LO;
+
+ # ifdef HAVE_STRUCT_UTIMBUF
+- tbuf.actime = time(NULL);
++ tbuf.actime = atime;
+ tbuf.modtime = modtime;
+ return utime(fname, &tbuf);
+ # else
+- t[0] = time(NULL);
++ t[0] = atime;
+ t[1] = modtime;
+ return utime(fname, t);
+ # endif
diff --git a/testsuite/atimes.test b/testsuite/atimes.test
new file mode 100644
--- /dev/null
diff --git a/testsuite/rsync.fns b/testsuite/rsync.fns
--- a/testsuite/rsync.fns
+++ b/testsuite/rsync.fns
-@@ -219,6 +219,10 @@ checkit() {
+@@ -220,6 +220,10 @@ checkit() {
# We can just write everything to stdout/stderr, because the
# wrapper hides it unless there is a problem.
echo "Running: \"$1\""
eval "$1"
status=$?
-@@ -226,10 +230,13 @@ checkit() {
- failed="YES";
+@@ -227,10 +231,13 @@ checkit() {
+ failed="$failed status=$status"
fi
+ if test x$TLS_ARGS != x--atimes; then
echo ""
- ( cd "$2" && rsync_ls_lR . ) > "$tmpdir/ls-from"
( cd "$3" && rsync_ls_lR . ) > "$tmpdir/ls-to"
- diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed=YES
+ diff $diffopt "$tmpdir/ls-from" "$tmpdir/ls-to" || failed="$failed dir-diff"
diff --git a/tls.c b/tls.c
--- a/tls.c
diff --git a/util.c b/util.c
--- a/util.c
+++ b/util.c
-@@ -123,7 +123,7 @@ NORETURN void overflow_exit(const char *str)
- exit_cleanup(RERR_MALLOC);
- }
+@@ -125,20 +125,24 @@ NORETURN void overflow_exit(const char *str)
+ /* This returns 0 for success, 1 for a symlink if symlink time-setting
+ * is not possible, or -1 for any other error. */
-int set_modtime(const char *fname, time_t modtime, mode_t mode)
+int set_times(const char *fname, time_t modtime, time_t atime, mode_t mode)
{
- #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
- if (S_ISLNK(mode))
-@@ -131,9 +131,13 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode)
- #endif
+ static int switch_step = 0;
if (verbose > 2) {
- rprintf(FINFO, "set modtime of %s to (%ld) %s",
+ mtimebuf, (long)atime, timestring(atime));
}
- if (dry_run)
-@@ -142,7 +146,7 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode)
- {
+ switch (switch_step) {
+ #ifdef HAVE_UTIMENSAT
+ #include "case_N.h"
+- if (do_utimensat(fname, modtime, 0) == 0)
++ if (do_utimensat(fname, modtime, 0, atime, 0) == 0)
+ break;
+ if (errno != ENOSYS)
+ return -1;
+@@ -148,7 +152,7 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode)
+
+ #ifdef HAVE_LUTIMES
+ #include "case_N.h"
+- if (do_lutimes(fname, modtime, 0) == 0)
++ if (do_lutimes(fname, modtime, 0, atime, 0) == 0)
+ break;
+ if (errno != ENOSYS)
+ return -1;
+@@ -167,10 +171,10 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode)
+
+ #include "case_N.h"
#ifdef HAVE_UTIMES
- struct timeval t[2];
-- t[0].tv_sec = time(NULL);
-+ t[0].tv_sec = atime;
- t[0].tv_usec = 0;
- t[1].tv_sec = modtime;
- t[1].tv_usec = 0;
-@@ -156,12 +160,12 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode)
- return utimes(fname, t);
- #elif defined HAVE_STRUCT_UTIMBUF
- struct utimbuf tbuf;
-- tbuf.actime = time(NULL);
-+ tbuf.actime = atime;
- tbuf.modtime = modtime;
- return utime(fname,&tbuf);
- #elif defined HAVE_UTIME
- time_t t[2];
-- t[0] = time(NULL);
-+ t[0] = atime;
- t[1] = modtime;
- return utime(fname,t);
+- if (do_utimes(fname, modtime, 0) == 0)
++ if (do_utimes(fname, modtime, 0, atime, 0) == 0)
+ break;
#else
+- if (do_utime(fname, modtime, 0) == 0)
++ if (do_utime(fname, modtime, 0, atime, 0) == 0)
+ break;
+ #endif
+