cb0f6bd
Optionally preserve atimes.
cb0f6bd
    
cb0f6bd
Based on https://bugzilla.samba.org/show_bug.cgi?id=7249#c1 by Nicolas George.
cb0f6bd
cb0f6bd
Index: rsync-3.1.0/options.c
cb0f6bd
===================================================================
cb0f6bd
--- rsync-3.1.0.orig/options.c
cb0f6bd
+++ rsync-3.1.0/options.c
cb0f6bd
@@ -125,6 +125,7 @@ int delay_updates = 0;
cb0f6bd
 long block_size = 0; /* "long" because popt can't set an int32. */
cb0f6bd
 char *skip_compress = NULL;
cb0f6bd
 item_list dparam_list = EMPTY_ITEM_LIST;
cb0f6bd
+int noatime = 0;
cb0f6bd
 
cb0f6bd
 /** Network address family. **/
cb0f6bd
 int default_af_hint
cb0f6bd
@@ -802,6 +803,7 @@ void usage(enum logcode F)
cb0f6bd
   rprintf(F,"     --iconv=CONVERT_SPEC    request charset conversion of filenames\n");
cb0f6bd
 #endif
cb0f6bd
   rprintf(F,"     --checksum-seed=NUM     set block/file checksum seed (advanced)\n");
cb0f6bd
+  rprintf(F,"     --noatime               do not alter atime when opening source files\n");
cb0f6bd
   rprintf(F," -4, --ipv4                  prefer IPv4\n");
cb0f6bd
   rprintf(F," -6, --ipv6                  prefer IPv6\n");
cb0f6bd
   rprintf(F,"     --version               print version number\n");
cb0f6bd
@@ -1019,6 +1021,7 @@ static struct poptOption long_options[]
cb0f6bd
   {"iconv",            0,  POPT_ARG_STRING, &iconv_opt, 0, 0, 0 },
cb0f6bd
   {"no-iconv",         0,  POPT_ARG_NONE,   0, OPT_NO_ICONV, 0, 0 },
cb0f6bd
 #endif
cb0f6bd
+  {"noatime",          0,  POPT_ARG_VAL,    &noatime, 1, 0, 0 },
cb0f6bd
   {"ipv4",            '4', POPT_ARG_VAL,    &default_af_hint, AF_INET, 0, 0 },
cb0f6bd
   {"ipv6",            '6', POPT_ARG_VAL,    &default_af_hint, AF_INET6, 0, 0 },
cb0f6bd
   {"8-bit-output",    '8', POPT_ARG_VAL,    &allow_8bit_chars, 1, 0, 0 },
cb0f6bd
@@ -2739,6 +2742,12 @@ void server_options(char **args, int *ar
cb0f6bd
 	if (preallocate_files && am_sender)
cb0f6bd
 		args[ac++] = "--preallocate";
cb0f6bd
 
cb0f6bd
+	/*
cb0f6bd
+	 * Do we want remote atime preservation when we preserve local ones?
cb0f6bd
+	if (noatime)
cb0f6bd
+		args[ac++] = "--noatime";
cb0f6bd
+	*/
cb0f6bd
+
cb0f6bd
 	if (ac > MAX_SERVER_ARGS) { /* Not possible... */
cb0f6bd
 		rprintf(FERROR, "argc overflow in server_options().\n");
cb0f6bd
 		exit_cleanup(RERR_MALLOC);
cb0f6bd
Index: rsync-3.1.0/rsync.yo
cb0f6bd
===================================================================
cb0f6bd
--- rsync-3.1.0.orig/rsync.yo
cb0f6bd
+++ rsync-3.1.0/rsync.yo
cb0f6bd
@@ -454,6 +454,7 @@ to the detailed description below for a
cb0f6bd
      --protocol=NUM          force an older protocol version to be used
cb0f6bd
      --iconv=CONVERT_SPEC    request charset conversion of filenames
cb0f6bd
      --checksum-seed=NUM     set block/file checksum seed (advanced)
cb0f6bd
+     --noatime               do not alter atime when opening source files
cb0f6bd
  -4, --ipv4                  prefer IPv4
cb0f6bd
  -6, --ipv6                  prefer IPv6
cb0f6bd
      --version               print version number
cb0f6bd
@@ -2543,6 +2544,13 @@ daemon uses the charset specified in its
cb0f6bd
 regardless of the remote charset you actually pass.  Thus, you may feel free to
cb0f6bd
 specify just the local charset for a daemon transfer (e.g. bf(--iconv=utf8)).
cb0f6bd
 
cb0f6bd
+dit(bf(--noatime)) Use the O_NOATIME open flag on systems that support it.
cb0f6bd
+The effect of this flag is to avoid altering the access time (atime) of the
cb0f6bd
+opened files.
cb0f6bd
+If the system does not support the O_NOATIME flag, this option does nothing.
cb0f6bd
+Currently, systems known to support O_NOATIME are Linux >= 2.6.8 with glibc
cb0f6bd
+>= 2.3.4.
cb0f6bd
+
cb0f6bd
 dit(bf(-4, --ipv4) or bf(-6, --ipv6)) Tells rsync to prefer IPv4/IPv6
cb0f6bd
 when creating sockets.  This only affects sockets that rsync has direct
cb0f6bd
 control over, such as the outgoing socket when directly contacting an
46b2056
diff --git a/syscall.c b/syscall.c
46b2056
index c46a8b4..6620563 100644
46b2056
--- a/syscall.c
46b2056
+++ b/syscall.c
46b2056
@@ -42,6 +42,7 @@ extern int inplace;
46b2056
 extern int preallocate_files;
cb0f6bd
 extern int preserve_perms;
cb0f6bd
 extern int preserve_executability;
cb0f6bd
+extern int noatime;
cb0f6bd
 
46b2056
 #ifndef S_BLKSIZE
46b2056
 # if defined hpux || defined __hpux__ || defined __hpux
cb0f6bd
@@ -189,6 +190,10 @@ int do_open(const char *pathname, int fl
cb0f6bd
 		RETURN_ERROR_IF(dry_run, 0);
cb0f6bd
 		RETURN_ERROR_IF_RO_OR_LO;
cb0f6bd
 	}
cb0f6bd
+#ifdef O_NOATIME
cb0f6bd
+	if (noatime)
cb0f6bd
+		flags |= O_NOATIME;
cb0f6bd
+#endif
cb0f6bd
 
cb0f6bd
 	return open(pathname, flags | O_BINARY, mode);
cb0f6bd
 }
ffcb495
Index: rsync/tls.c
ffcb495
===================================================================
ffcb495
--- rsync.orig/tls.c
ffcb495
+++ rsync/tls.c
ffcb495
@@ -53,6 +53,7 @@ int preserve_perms = 0;
ffcb495
 int preserve_executability = 0;
ffcb495
 int preallocate_files = 0;
ffcb495
 int inplace = 0;
ffcb495
+int noatime = 0;
ffcb495
 
ffcb495
 #ifdef SUPPORT_XATTRS
ffcb495
 
ffcb495
Index: rsync/t_unsafe.c
ffcb495
===================================================================
ffcb495
--- rsync.orig/t_unsafe.c
ffcb495
+++ rsync/t_unsafe.c
ffcb495
@@ -33,6 +33,10 @@ int preserve_perms = 0;
ffcb495
 int preserve_executability = 0;
ffcb495
 short info_levels[COUNT_INFO], debug_levels[COUNT_DEBUG];
ffcb495
 
ffcb495
+/* This is to make syscall.o shut up. */
ffcb495
+int noatime = 0;
ffcb495
+
ffcb495
+
ffcb495
 int
ffcb495
 main(int argc, char **argv)
ffcb495
 {
ffcb495
Index: rsync/wildtest.c
ffcb495
===================================================================
ffcb495
--- rsync.orig/wildtest.c
ffcb495
+++ rsync/wildtest.c
ffcb495
@@ -32,6 +32,9 @@ int fnmatch_errors = 0;
ffcb495
 
ffcb495
 int wildmatch_errors = 0;
ffcb495
 
ffcb495
+/* This is to make syscall.o shut up. */
ffcb495
+int noatime = 0;
ffcb495
+
ffcb495
 typedef char bool;
ffcb495
 
ffcb495
 int output_iterations = 0;
ffcb495
Index: rsync/trimslash.c
ffcb495
===================================================================
ffcb495
--- rsync.orig/trimslash.c
ffcb495
+++ rsync/trimslash.c
ffcb495
@@ -30,6 +30,7 @@ int preserve_perms = 0;
ffcb495
 int preserve_executability = 0;
ffcb495
 int preallocate_files = 0;
ffcb495
 int inplace = 0;
ffcb495
+int noatime = 0;
ffcb495
 
ffcb495
 int
ffcb495
 main(int argc, char **argv)