]> git.wh0rd.org Git - nano.git/commitdiff
fix various file-saving bugs
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Wed, 18 Apr 2007 19:09:44 +0000 (19:09 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Wed, 18 Apr 2007 19:09:44 +0000 (19:09 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4081 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/files.c

index 8024008799d106c17ba9a72fa7f445c9f0b570dd..4720ead5210190bf3a29678993efaf0d3adbd310 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,12 @@ CVS code -
          would be treated as "~daemon/"). (DLR, found by Justin
          Fletcher)
        - Simplify. (DLR)
+  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. (DLR)
+       - Rename variable different_name to do_warning, for clarity.
+         (DLR)
   input_tab()
        - Don't bother checking if num_matches is less than zero, as
          it's a size_t and hence unsigned. (DLR)
index 2cd54d2fce00c165a9debe64c40ebb41149bb508..c5fbdbf1632e101cfc4d5de97da882dbe01b1f40 100644 (file)
@@ -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