From 6d8ca962dccb44ee3cb0caa2ad487c94add307c9 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 12 Sep 2021 09:54:31 +0200
Subject: [PATCH 19/34] files: write a lock file also for a freshly saved
 buffer

This fixes https://savannah.gnu.org/bugs/?61146

Bug existed since version 2.3.2, since --locking was introduced,
and continued to exist since version 4.8 despite commit 497f126b
claiming to have fixed it.
---
 src/files.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/files.c b/src/files.c
index 582965c6..8156dd85 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1947,8 +1947,10 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
 			if (openfile->lock_filename != NULL) {
 				delete_lockfile(openfile->lock_filename);
 				free(openfile->lock_filename);
-				openfile->lock_filename = do_lockfile(realname, FALSE);
 			}
+
+			if (ISSET(LOCKING))
+				openfile->lock_filename = do_lockfile(realname, FALSE);
 #endif
 			openfile->filename = mallocstrcpy(openfile->filename, realname);
 #ifdef ENABLE_COLOR
-- 
2.29.3

