summaryrefslogtreecommitdiff
path: root/src/filelock.c
diff options
context:
space:
mode:
authorMatt Armstrong <matt@rfc20.org>2021-02-19 15:39:15 -0800
committerEli Zaretskii <eliz@gnu.org>2021-03-27 12:17:31 +0300
commitc4ab173df3ea4c37165c011c515928da1783a9ae (patch)
tree904f450d63ff41d30ef07fa5a8adbea0d747a703 /src/filelock.c
parenta443a379c54158f49efd8542632c4e9478aa1117 (diff)
downloademacs-c4ab173df3ea4c37165c011c515928da1783a9ae.tar.gz
File unlock errors now issue warnings (Bug#46397)
The primary idea is to allow `kill-buffer' and `kill-emacs' to complete even if Emacs has trouble unlocking the buffer's file. * lisp/userlock.el (userlock--handle-unlock-error): New function, call `display-error'. * src/filelock.c (unlock_file_body): New function, do what 'unlock_file' used to. (unlock_file_handle_error): New function, call `userlock--handle-unlock-error' with the captured error. (unlock_file): Handle `file-error' conditions by calling the handler defined above. * test/src/filelock-tests.el (filelock-tests-kill-buffer-spoiled): (filelock-tests-unlock-spoiled): Modify to test new behavior.
Diffstat (limited to 'src/filelock.c')
-rw-r--r--src/filelock.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 373fc00a42c..446a262a1ce 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -719,8 +719,8 @@ lock_file (Lisp_Object fn)
}
}
-void
-unlock_file (Lisp_Object fn)
+static Lisp_Object
+unlock_file_body (Lisp_Object fn)
{
char *lfname;
USE_SAFE_ALLOCA;
@@ -737,6 +737,23 @@ unlock_file (Lisp_Object fn)
report_file_errno ("Unlocking file", filename, err);
SAFE_FREE ();
+ return Qnil;
+}
+
+static Lisp_Object
+unlock_file_handle_error (Lisp_Object err)
+{
+ call1 (intern ("userlock--handle-unlock-error"), err);
+ return Qnil;
+}
+
+void
+unlock_file (Lisp_Object fn)
+{
+ internal_condition_case_1 (unlock_file_body,
+ fn,
+ list1(Qfile_error),
+ unlock_file_handle_error);
}
#else /* MSDOS */
@@ -790,7 +807,10 @@ DEFUN ("unlock-buffer", Funlock_buffer, Sunlock_buffer,
0, 0, 0,
doc: /* Unlock the file visited in the current buffer.
If the buffer is not modified, this does nothing because the file
-should not be locked in that case. */)
+should not be locked in that case. It also does nothing if the
+current buffer is not visiting a file, or is not locked. Handles file
+system errors by calling `display-warning' and continuing as if the
+error did not occur. */)
(void)
{
if (SAVE_MODIFF < MODIFF