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.master
parent
4687322398
commit
497f126bb2
11
src/files.c
11
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. */
|
/* When having written an entire buffer, update some administrivia. */
|
||||||
if (fullbuffer && method == OVERWRITE && !tmp) {
|
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) {
|
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
|
#ifdef ENABLE_COLOR
|
||||||
const char *oldname, *newname;
|
const char *oldname, *newname;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue