From 6948d2e7792a0c02b30f649ace60ded83686092f Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Wed, 14 Jan 2015 02:36:30 +0000
Subject: [PATCH] 2015-01-13  Chris Allegretta <chrisa@asty.org>         *
 src/files.c (open_buffer): Check here for locking and properly         handle
 choosing to not open a file when locked instead of in         open_file(). 
 Fixes Savannah bug 42373 reported by Benno Schulenberg

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5104 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog   |  5 +++++
 src/files.c | 28 +++++++++++++++++-----------
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 484070d0..2504b8f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-13  Chris Allegretta <chrisa@asty.org>
+	* src/files.c (open_buffer): Check here for locking and properly
+	handle choosing to not open a file when locked instead of in
+	open_file().  Fixes Savannah bug 42373 reported by Benno Schulenberg
+
 GNU nano 2.3.99pre1 - 2015.01.06
 2015-01-03  Chris Allegretta <chrisa@asty.org>
 	* New formatter code to support syntaxes like
diff --git a/src/files.c b/src/files.c
index b3e65413..97494bc0 100644
--- a/src/files.c
+++ b/src/files.c
@@ -337,9 +337,25 @@ void open_buffer(const char *filename, bool undoable)
 
     /* If we're loading into a new buffer, add a new entry to
      * openfile. */
-    if (new_buffer)
+    if (new_buffer) {
 	make_new_buffer();
 
+#ifndef NANO_TINY
+	if (ISSET(LOCKING) && filename[0] != '\0') {
+	    int lockstatus = do_lockfile(filename);
+	    if (lockstatus < 0) {
+		if (openfile->next) {
+		    close_buffer();
+		    statusbar(_("Cancelled"));
+		    return;
+		} else
+		    filename = "";
+	    }
+ 	}
+#endif
+    }
+
+
     /* 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)) ?
@@ -906,16 +922,6 @@ int open_file(const char *filename, bool newfie, FILE **f)
 	full_filename = mallocstrcpy(NULL, filename);
 
 
-#ifndef NANO_TINY
-    if (ISSET(LOCKING)) {
-	int lockstatus = do_lockfile(full_filename);
-        if (lockstatus < 0)
-	    return -1;
-	else if (lockstatus == 0)
-	    quiet = 1;
-    }
-#endif
-
     if (stat(full_filename, &fileinfo) == -1) {
 	/* Well, maybe we can open the file even if the OS says it's
 	 * not there. */
-- 
GitLab