Blame SOURCES/0002-use-futimens-if-available-instead-of-utime.patch

958069
From 23510b930ea31f7de8005e2f0ff6cab7062b4e26 Mon Sep 17 00:00:00 2001
958069
From: Kamil Dudka <kdudka@redhat.com>
958069
Date: Thu, 19 Aug 2010 15:23:06 +0200
958069
Subject: [PATCH 2/2] use futimens() if available, instead of utime()
958069
958069
---
958069
 configure.ac |    2 +-
958069
 src/files.c  |   48 +++++++++++++++++++++++++++++++++++-------------
958069
 2 files changed, 36 insertions(+), 14 deletions(-)
958069
958069
diff --git a/configure.ac b/configure.ac
958069
index 66f8ee3..f4975d3 100644
958069
--- a/configure.ac
958069
+++ b/configure.ac
958069
@@ -415,7 +415,7 @@ fi])
958069
 
958069
 dnl Checks for functions.
958069
 
958069
-AC_CHECK_FUNCS(getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen vsnprintf)
958069
+AC_CHECK_FUNCS(futimens getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen vsnprintf)
958069
 
958069
 if test x$enable_utf8 != xno; then
958069
     AC_CHECK_FUNCS(iswalnum iswblank iswpunct iswspace nl_langinfo mblen mbstowcs mbtowc wctomb wcwidth)
958069
diff --git a/src/files.c b/src/files.c
958069
index 99cc1b8..9a1bdcc 100644
958069
--- a/src/files.c
958069
+++ b/src/files.c
958069
@@ -1455,6 +1455,29 @@ int copy_file(FILE *inn, FILE *out)
958069
     return retval;
958069
 }
958069
 
958069
+#ifdef HAVE_FUTIMENS
958069
+/* set atime/mtime by file descriptor */
958069
+int utime_wrap(int fd, const char *filename, struct utimbuf *ut)
958069
+{
958069
+    struct timespec times[2];
958069
+    (void) filename;
958069
+
958069
+    times[0].tv_sec = ut->actime;
958069
+    times[1].tv_sec = ut->modtime;
958069
+    times[0].tv_nsec = 0L;
958069
+    times[1].tv_nsec = 0L;
958069
+
958069
+    return futimens(fd, times);
958069
+}
958069
+#else
958069
+/* set atime/mtime by file name */
958069
+int utime_wrap(int fd, const char *filename, struct utimbuf *ut)
958069
+{
958069
+    (void) fd;
958069
+    return utime(filename, ut);
958069
+}
958069
+#endif
958069
+
958069
 /* Write a file out to disk.  If f_open isn't NULL, we assume that it is
958069
  * a stream associated with the file, and we don't try to open it
958069
  * ourselves.  If tmp is TRUE, we set the umask to disallow anyone else
958069
@@ -1694,6 +1717,18 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
958069
 	fprintf(stderr, "Backing up %s to %s\n", realname, backupname);
958069
 #endif
958069
 
958069
+	/* Set backup's file metadata. */
958069
+	if (utime_wrap(backup_fd, backupname, &filetime) == -1
958069
+		&& !ISSET(INSECURE_BACKUP)) {
958069
+	    statusbar(_("Error writing backup file %s: %s"), backupname,
958069
+			strerror(errno));
958069
+	    /* If we can't write to the backup, DONT go on, since
958069
+	       whatever caused the backup file to fail (e.g. disk
958069
+	       full may well cause the real file write to fail, which
958069
+	       means we could lose both the backup and the original! */
958069
+	    goto cleanup_and_exit;
958069
+	}
958069
+
958069
 	/* Copy the file. */
958069
 	copy_status = copy_file(f, backup_file);
958069
 
958069
@@ -1704,19 +1739,6 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
958069
 	    goto cleanup_and_exit;
958069
 	}
958069
 
958069
-	/* And set its metadata. */
958069
-	if (utime(backupname, &filetime) == -1 && !ISSET(INSECURE_BACKUP)) {
958069
-	    if (prompt_failed_backupwrite(backupname))
958069
-		goto skip_backup;
958069
-	    statusbar(_("Error writing backup file %s: %s"), backupname,
958069
-			strerror(errno));
958069
-	    /* If we can't write to the backup, DONT go on, since
958069
-	       whatever caused the backup file to fail (e.g. disk
958069
-	       full may well cause the real file write to fail, which
958069
-	       means we could lose both the backup and the original! */
958069
-	    goto cleanup_and_exit;
958069
-	}
958069
-
958069
 	free(backupname);
958069
     }
958069
 
958069
-- 
958069
1.7.4
958069