From b8dfcb3896ccc8c302a6c0a28c111c3c9e70099b Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Wed, 18 Apr 2007 19:09:44 +0000 Subject: [PATCH] fix various file-saving bugs git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4081 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/files.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3cc352e4..96ba3596 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,11 @@ whenever possible, so that ~user/file.txt and "~user/file.txt" are treated the same way if ~user is a user's home directory. * files.c (real_dir_from_tilde): Simplify. + * files.c (do_writeout): Properly display the warning in all + cases if we try to save (a) an existing file under a different + name, or (b) a file with no name under an existing file's name. + * files.c (do_writeout): Rename variable different_name to + do_warning, for clarity. * rcfile.c (parse_include): Open files using their full paths whenever possible, so that ~user/file.txt and "~user/file.txt" are treated the same way if ~user is a user's home directory. diff --git a/src/files.c b/src/files.c index 2cd54d2f..c5fbdbf1 100644 --- a/src/files.c +++ b/src/files.c @@ -1892,7 +1892,7 @@ bool do_writeout(bool exiting) if (append == OVERWRITE) { size_t answer_len = strlen(answer); - bool name_exists, different_name; + bool name_exists, do_warning; char *full_answer, *full_filename; struct stat st; @@ -1900,12 +1900,14 @@ bool do_writeout(bool exiting) * full path. */ sunder(answer); - name_exists = (stat(answer, &st) != -1); full_answer = get_full_path(answer); full_filename = get_full_path(openfile->filename); - different_name = (strcmp((full_answer == NULL) ? + name_exists = (stat((full_answer == NULL) ? answer : + full_answer, &st) != -1); + do_warning = ((openfile->filename[0] == '\0' && + name_exists) || (strcmp((full_answer == NULL) ? answer : full_answer, (full_filename == NULL) ? - openfile->filename : full_filename) != 0); + openfile->filename : full_filename) != 0)); /* Convert nulls to newlines. answer_len is the * string's real length. */ @@ -1916,7 +1918,7 @@ bool do_writeout(bool exiting) if (full_answer != NULL) free(full_answer); - if (different_name) { + if (do_warning) { if (name_exists) { /* If we're using restricted mode, we aren't * allowed to save a new file under the name of -- 2.39.5