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

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