From 5e24771a1615ff474e97340a4fa6c2a4d49d6671 Mon Sep 17 00:00:00 2001 From: Viorel Bota Date: Thu, 21 Sep 2017 01:37:34 +0300 Subject: [PATCH] 002 fix for: "bug #51040: when using 'savefile' or --tempfile" Signed-off-by: Viorel Bota --- src/files.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/files.c b/src/files.c index d212624..fa60fe9 100644 --- a/src/files.c +++ b/src/files.c @@ -2046,12 +2046,6 @@ int do_writeout(bool exiting) /* Display newlines in filenames as ^J. */ as_an_at = FALSE; - if (exiting && ISSET(TEMP_FILE) && openfile->filename[0] != '\0') { - if (write_file(openfile->filename, NULL, FALSE, OVERWRITE, FALSE)) - return 1; - /* If writing the file failed, go on to prompt for a new name. */ - } - given = mallocstrcpy(NULL, #ifndef NANO_TINY (openfile->mark_set && !exiting) ? "" : @@ -2059,6 +2053,11 @@ int do_writeout(bool exiting) openfile->filename); while (TRUE) { + /*If TEMP_FILE flag is set + *pretend the user chose to save under the same name*/ + if (ISSET(TEMP_FILE)) + answer = mallocstrcpy(answer, openfile->filename); + else { const char *msg; #ifndef NANO_TINY const char *formatstr, *backupstr; @@ -2100,6 +2099,7 @@ int do_writeout(bool exiting) "", "" #endif ); + } if (i < 0) { statusbar(_("Cancelled")); @@ -2236,9 +2236,28 @@ int do_writeout(bool exiting) warn_and_shortly_pause(_("File on disk has changed")); - if (do_yesno_prompt(FALSE, _("File was modified since " - "you opened it; continue saving? ")) < 1) - continue; + int response = do_yesno_prompt(FALSE, _("File was modified since " + "you opened it; continue saving? ")); + + if (ISSET(TEMP_FILE)) + { + /* If option "Yes" was selected, + * write file */ + if ( 1==response ) + { + if (write_file(openfile->filename, NULL, FALSE, OVERWRITE, FALSE)) + return 1; + } + /* If option "No" was selected, + * return 2 to discard buffer */ + else if ( 0==response ) + return 2; + /* return 0 to indicate writing error */ + else + return 0; + } + else if ( response < 1) + continue; } #endif } -- 2.7.4