From 497f126bb2d7d1a5cb7d612f075c777b4ee6bfde Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 13 Jan 2020 19:10:23 +0100 Subject: [PATCH] files: write a lock file also for a new file and when the name changed (When the new or changed name is that of an existing file AND this file is being edited by some other editor (or nano itself), then the behavior is rather strange: nano asks whether to continue, but the file has already been overwritten and there is nothing the user can do to cancel or revert things. A later commit should improve this.) This fixes https://savannah.gnu.org/bugs/?47975, and fixes https://savannah.gnu.org/bugs/?53883. --- src/files.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index bc7174af..90fe7f4d 100644 --- a/src/files.c +++ b/src/files.c @@ -1867,8 +1867,17 @@ bool write_file(const char *name, FILE *thefile, bool tmp, /* When having written an entire buffer, update some administrivia. */ if (fullbuffer && method == OVERWRITE && !tmp) { - /* If the filename was changed, check if this means a new syntax. */ + /* If the filename was changed, write a new lockfile when needed, + * and check whether it means a different syntax gets used. */ if (strcmp(openfile->filename, realname) != 0) { +#ifndef NANO_TINY + if (openfile->lock_filename != NULL) { + delete_lockfile(openfile->lock_filename); + free(openfile->lock_filename); + openfile->lock_filename = NULL; + do_lockfile(realname); + } +#endif #ifdef ENABLE_COLOR const char *oldname, *newname;