From c9b6c8dac1bc0fd7ece202d2d7acccb8279d053e Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 28 Aug 2014 10:45:28 +0200 Subject: [PATCH] fish: edit: return 1 for unchanged file 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 0170dafc5..f43ef3b02 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 8efa45285..3a9dd2dab 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 6622b3ad8..1d401c67a 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);