2011-03-03 11:05:56 +00:00
|
|
|
From 23510b930ea31f7de8005e2f0ff6cab7062b4e26 Mon Sep 17 00:00:00 2001
|
2010-11-22 22:15:06 +00:00
|
|
|
From: Kamil Dudka <kdudka@redhat.com>
|
|
|
|
Date: Thu, 19 Aug 2010 15:23:06 +0200
|
2014-05-29 07:23:07 +00:00
|
|
|
Subject: [PATCH 3/3] use futimens() if available, instead of utime()
|
2010-11-22 22:15:06 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
config.h.in | 3 +++
|
|
|
|
configure | 2 +-
|
|
|
|
configure.ac | 2 +-
|
2015-01-05 13:21:03 +00:00
|
|
|
src/files.c | 48 ++++++++++++++++++++++++++++++++++++------------
|
|
|
|
4 files changed, 41 insertions(+), 14 deletions(-)
|
2010-11-22 22:15:06 +00:00
|
|
|
|
|
|
|
diff --git a/config.h.in b/config.h.in
|
2011-03-03 11:05:56 +00:00
|
|
|
index 52e13f1..cb17b29 100644
|
2010-11-22 22:15:06 +00:00
|
|
|
--- a/config.h.in
|
|
|
|
+++ b/config.h.in
|
2014-07-16 12:38:58 +00:00
|
|
|
@@ -69,6 +69,9 @@
|
2010-11-22 22:15:06 +00:00
|
|
|
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
|
|
|
#undef HAVE_DOPRNT
|
|
|
|
|
|
|
|
+/* Define to 1 if you have the `futimens' function. */
|
|
|
|
+#undef HAVE_FUTIMENS
|
|
|
|
+
|
|
|
|
/* Define to 1 if you have the `getdelim' function. */
|
|
|
|
#undef HAVE_GETDELIM
|
|
|
|
|
|
|
|
diff --git a/configure b/configure
|
2011-03-03 11:05:56 +00:00
|
|
|
index 02733c7..1805e53 100755
|
2010-11-22 22:15:06 +00:00
|
|
|
--- a/configure
|
|
|
|
+++ b/configure
|
2015-03-23 09:27:22 +00:00
|
|
|
@@ -7755,7 +7755,7 @@ fi
|
2010-11-22 22:15:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-29 07:23:07 +00:00
|
|
|
-for ac_func in getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen snprintf vsnprintf
|
|
|
|
+for ac_func in futimens getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen snprintf vsnprintf
|
2010-11-22 22:15:06 +00:00
|
|
|
do :
|
|
|
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
|
|
|
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
|
|
|
diff --git a/configure.ac b/configure.ac
|
2011-03-03 11:05:56 +00:00
|
|
|
index 66f8ee3..f4975d3 100644
|
2010-11-22 22:15:06 +00:00
|
|
|
--- a/configure.ac
|
|
|
|
+++ b/configure.ac
|
2014-07-17 20:33:02 +00:00
|
|
|
@@ -428,7 +428,7 @@ int main(void)
|
2010-11-22 22:15:06 +00:00
|
|
|
|
|
|
|
dnl Checks for functions.
|
|
|
|
|
2014-05-29 07:23:07 +00:00
|
|
|
-AC_CHECK_FUNCS(getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen snprintf vsnprintf)
|
|
|
|
+AC_CHECK_FUNCS(futimens getdelim getline isblank strcasecmp strcasestr strncasecmp strnlen snprintf vsnprintf)
|
2010-11-22 22:15:06 +00:00
|
|
|
|
2014-05-29 07:23:07 +00:00
|
|
|
if test "x$enable_utf8" != xno; then
|
2010-11-22 22:15:06 +00:00
|
|
|
AC_CHECK_FUNCS(iswalnum iswblank iswpunct iswspace nl_langinfo mblen mbstowcs mbtowc wctomb wcwidth)
|
|
|
|
diff --git a/src/files.c b/src/files.c
|
2011-03-03 11:05:56 +00:00
|
|
|
index 99cc1b8..9a1bdcc 100644
|
2010-11-22 22:15:06 +00:00
|
|
|
--- a/src/files.c
|
|
|
|
+++ b/src/files.c
|
2015-07-07 07:33:52 +00:00
|
|
|
@@ -1672,6 +1672,29 @@ int copy_file(FILE *inn, FILE *out)
|
2010-11-22 22:15:06 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef HAVE_FUTIMENS
|
|
|
|
+/* set atime/mtime by file descriptor */
|
|
|
|
+int utime_wrap(int fd, const char *filename, struct utimbuf *ut)
|
|
|
|
+{
|
|
|
|
+ struct timespec times[2];
|
|
|
|
+ (void) filename;
|
|
|
|
+
|
|
|
|
+ times[0].tv_sec = ut->actime;
|
|
|
|
+ times[1].tv_sec = ut->modtime;
|
|
|
|
+ times[0].tv_nsec = 0L;
|
|
|
|
+ times[1].tv_nsec = 0L;
|
|
|
|
+
|
|
|
|
+ return futimens(fd, times);
|
|
|
|
+}
|
|
|
|
+#else
|
|
|
|
+/* set atime/mtime by file name */
|
|
|
|
+int utime_wrap(int fd, const char *filename, struct utimbuf *ut)
|
|
|
|
+{
|
|
|
|
+ (void) fd;
|
|
|
|
+ return utime(filename, ut);
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Write a file out to disk. If f_open isn't NULL, we assume that it is
|
|
|
|
* a stream associated with the file, and we don't try to open it
|
|
|
|
* ourselves. If tmp is TRUE, we set the umask to disallow anyone else
|
2015-07-07 07:33:52 +00:00
|
|
|
@@ -1913,18 +1936,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
2015-01-05 13:21:03 +00:00
|
|
|
fprintf(stderr, "Backing up %s to %s\n", realname, backupname);
|
|
|
|
#endif
|
2010-11-28 20:01:32 +00:00
|
|
|
|
2015-01-05 13:21:03 +00:00
|
|
|
- /* Copy the file. */
|
|
|
|
- copy_status = copy_file(f, backup_file);
|
|
|
|
-
|
|
|
|
- if (copy_status != 0) {
|
|
|
|
- statusbar(_("Error reading %s: %s"), realname,
|
|
|
|
- strerror(errno));
|
|
|
|
- beep();
|
|
|
|
- goto cleanup_and_exit;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* And set its metadata. */
|
2010-11-28 20:01:32 +00:00
|
|
|
- if (utime(backupname, &filetime) == -1 && !ISSET(INSECURE_BACKUP)) {
|
2015-01-05 13:21:03 +00:00
|
|
|
+ /* Set backup's file metadata. */
|
2014-05-29 07:23:07 +00:00
|
|
|
+ if (utime_wrap(backup_fd, backupname, &filetime) == -1
|
|
|
|
+ && !ISSET(INSECURE_BACKUP)) {
|
|
|
|
if (prompt_failed_backupwrite(backupname))
|
|
|
|
goto skip_backup;
|
|
|
|
statusbar(_("Error writing backup file %s: %s"), backupname,
|
2015-07-07 07:33:52 +00:00
|
|
|
@@ -1936,6 +1950,16 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
2015-01-05 13:21:03 +00:00
|
|
|
goto cleanup_and_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /* Copy the file. */
|
|
|
|
+ copy_status = copy_file(f, backup_file);
|
|
|
|
+
|
|
|
|
+ if (copy_status != 0) {
|
|
|
|
+ statusbar(_("Error reading %s: %s"), realname,
|
|
|
|
+ strerror(errno));
|
|
|
|
+ beep();
|
|
|
|
+ goto cleanup_and_exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
free(backupname);
|
|
|
|
}
|
|
|
|
|
2010-11-22 22:15:06 +00:00
|
|
|
--
|
2011-03-03 11:05:56 +00:00
|
|
|
1.7.4
|
2010-11-22 22:15:06 +00:00
|
|
|
|