[Libguestfs] [PATCH 08/13] fish: edit: return 1 for unchanged file

Pino Toscano ptoscano at redhat.com
Thu Aug 28 13:21:11 UTC 2014


Change the return value of edit_file_editor to 1, in case the editor did
not change the (temporary) file.
---
 fish/edit.c      | 2 +-
 fish/file-edit.c | 2 +-
 fish/file-edit.h | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fish/edit.c b/fish/edit.c
index 0170daf..f43ef3b 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -60,5 +60,5 @@ run_edit (const char *cmd, size_t argc, char *argv[])
 
   r = edit_file_editor (g, remotefilename, editor, NULL);
 
-  return r;
+  return r == -1 ? -1 : 0;
 }
diff --git a/fish/file-edit.c b/fish/file-edit.c
index 8efa452..3a9dd2d 100644
--- a/fish/file-edit.c
+++ b/fish/file-edit.c
@@ -101,7 +101,7 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
   /* Changed? */
   if (oldstat.st_ctime == newstat.st_ctime &&
       oldstat.st_size == newstat.st_size)
-    return 0;
+    return 1;
 
   /* Upload to a new file in the same directory, so if it fails we
    * don't end up with a partially written file.  Give the new file
diff --git a/fish/file-edit.h b/fish/file-edit.h
index 6622b3a..1d401c6 100644
--- a/fish/file-edit.h
+++ b/fish/file-edit.h
@@ -26,7 +26,8 @@
  * If 'backup_extension' is not null, then a copy of 'filename' is saved
  * with 'backup_extension' appended to its file name.
  *
- * Returns -1 for failure, 0 otherwise.
+ * Returns -1 for failure, 0 on success, 1 if the editor did not change
+ * the file (e.g. the user closed the editor without saving).
  */
 extern int edit_file_editor (guestfs_h *g, const char *filename,
                              const char *editor, const char *backup_extension);
-- 
1.9.3




More information about the Libguestfs mailing list