[Pkg-libvirt-commits] [libguestfs] 214/266: fish: edit: bring the fast-time-edit protection

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit f1c6d5d7f2b852c1d2ccee409c6ac58c02d2bfd2
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Thu Aug 28 11:02:53 2014 +0200

    fish: edit: bring the fast-time-edit protection
    
    Bring from virt-edit the small hack of putting the ctime of the
    temporary file few seconds back to notice file changes also on fast
    editing.
---
 fish/file-edit.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/fish/file-edit.c b/fish/file-edit.c
index 3a9dd2d..e2298eb 100644
--- a/fish/file-edit.c
+++ b/fish/file-edit.c
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <assert.h>
+#include <utime.h>
 
 #include "guestfs-internal-frontend.h"
 
@@ -49,6 +50,7 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
   CLEANUP_FREE char *cmd = NULL;
   struct stat oldstat, newstat;
   int r, fd;
+  struct utimbuf times;
 
   /* Download the file and write it to a temporary. */
   if (asprintf (&tmpfilename, "%s/libguestfsXXXXXX", tmpdir) == -1) {
@@ -74,6 +76,23 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
     return -1;
   }
 
+  /* Set the time back a few seconds on the original file.  This is so
+   * that if the user is very fast at editing, or if EDITOR is an
+   * automatic editor, then the edit might happen within the 1 second
+   * granularity of mtime, and we would think the file hasn't changed.
+   */
+  if (stat (tmpfilename, &oldstat) == -1) {
+    perror (tmpfilename);
+    return -1;
+  }
+
+  times.actime = oldstat.st_atime - 5;
+  times.modtime = oldstat.st_mtime - 5;
+  if (utime (tmpfilename, &times) == -1) {
+    perror ("utimes");
+    return -1;
+  }
+
   /* Get the old stat. */
   if (stat (tmpfilename, &oldstat) == -1) {
     perror (tmpfilename);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list