commit b63c90bf6b42be3d28b6fa46f7187060cde9ca0a
parent fa26889d0305f53dcd58c356090a37285e36a8e5
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 9 Feb 2020 17:35:00 +0100
locking: do not open an empty buffer when respecting the first lock file
When opening multiple files, and the first of them has a lock file,
and the user chooses to not open the corresponding file, then nano
should NOT create an empty buffer in its stead.
This fixes https://savannah.gnu.org/bugs/?57777.
Bug existed since lock files were introduced, in version 2.4.0,
specifically since commit 6948d2e7.
Diffstat:
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -373,6 +373,9 @@ bool open_buffer(const char *filename, bool new_buffer)
{
char *realname;
/* The filename after tilde expansion. */
+#ifndef NANO_TINY
+ char *thelocksname = NULL;
+#endif
struct stat fileinfo;
FILE *f;
int rc;
@@ -415,28 +418,24 @@ bool open_buffer(const char *filename, bool new_buffer)
/* If we're going to load into a new buffer, first create the new
* buffer and (if possible) lock the corresponding file. */
if (new_buffer) {
- make_new_buffer();
-
if (has_valid_path(realname)) {
#ifndef NANO_TINY
if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && filename[0] != '\0') {
- char *thelocksname = do_lockfile(realname, TRUE);
+ thelocksname = do_lockfile(realname, TRUE);
- /* When not overriding an existing lock, discard the buffer. */
+ /* When not overriding an existing lock, don't open a buffer. */
if (thelocksname == SKIPTHISFILE) {
-#ifdef ENABLE_MULTIBUFFER
- if (openfile != openfile->next)
- close_buffer();
-#endif
free(realname);
return FALSE;
- } else
- openfile->lock_filename = thelocksname;
+ }
}
#endif /* !NANO_TINY */
}
}
+ if (new_buffer)
+ make_new_buffer();
+
/* If the filename isn't blank, and we are not in NOREAD_MODE,
* open the file. Otherwise, treat it as a new file. */
rc = (filename[0] != '\0' && !ISSET(NOREAD_MODE)) ?
@@ -461,6 +460,9 @@ bool open_buffer(const char *filename, bool new_buffer)
* the filename and put the cursor at the start of the buffer. */
if (rc != -1 && new_buffer) {
openfile->filename = mallocstrcpy(openfile->filename, realname);
+#ifndef NANO_TINY
+ openfile->lock_filename = thelocksname;
+#endif
openfile->current = openfile->filetop;
openfile->current_x = 0;
openfile->placewewant = 0;