aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2023-07-24 18:08:40 +0300
committerEli Zaretskii2023-07-24 18:08:40 +0300
commit89558533683a100ca7946c4a35bf4ef50463efef (patch)
treefe55139d63546a04621a4d74de7e869fddd8c3c6
parentacebaa793f1b18ad54bccffe7ad07fef8e1cebe1 (diff)
downloademacs-89558533683a100ca7946c4a35bf4ef50463efef.tar.gz
emacs-89558533683a100ca7946c4a35bf4ef50463efef.zip
Don't signal error when locking a file from non file-visiting buffer
* lisp/userlock.el (userlock--check-content-unchanged): Support the case where a file is locked before being written to from a non file-visiting buffer. (Bug#64821)
-rw-r--r--lisp/userlock.el17
1 files changed, 12 insertions, 5 deletions
diff --git a/lisp/userlock.el b/lisp/userlock.el
index 562bc0a0a9f..96de17d54fd 100644
--- a/lisp/userlock.el
+++ b/lisp/userlock.el
@@ -110,10 +110,11 @@ You can <\\`q'>uit; don't modify this file."))
110 110
111(defun userlock--check-content-unchanged (filename) 111(defun userlock--check-content-unchanged (filename)
112 (with-demoted-errors "Unchanged content check: %S" 112 (with-demoted-errors "Unchanged content check: %S"
113 ;; Even tho we receive `filename', we know that `filename' refers to the current 113 ;; Even tho we receive `filename', we know that `filename' refers
114 ;; buffer's file. 114 ;; to the current buffer's file.
115 (cl-assert (equal (expand-file-name filename) 115 (cl-assert (or (null buffer-file-truename) ; temporary buffer
116 (expand-file-name buffer-file-truename))) 116 (equal (expand-file-name filename)
117 (expand-file-name buffer-file-truename))))
117 ;; Note: rather than read the file and compare to the buffer, we could save 118 ;; Note: rather than read the file and compare to the buffer, we could save
118 ;; the buffer and compare to the file, but for encrypted data this 119 ;; the buffer and compare to the file, but for encrypted data this
119 ;; wouldn't work well (and would risk exposing the data). 120 ;; wouldn't work well (and would risk exposing the data).
@@ -135,7 +136,13 @@ You can <\\`q'>uit; don't modify this file."))
135 (compare-buffer-substrings 136 (compare-buffer-substrings
136 buf start end 137 buf start end
137 (current-buffer) (point-min) (point-max)))))) 138 (current-buffer) (point-min) (point-max))))))
138 (set-visited-file-modtime) 139 ;; We know that some buffer visits FILENAME, because our
140 ;; caller (see lock_file) verified that. Thus, we set the
141 ;; modtime in that buffer, to cater to use case where the
142 ;; file is about to be written to from some buffer that
143 ;; doesn't visit any file, like a temporary buffer.
144 (with-current-buffer (get-file-buffer (file-truename filename))
145 (set-visited-file-modtime))
139 'unchanged))))) 146 'unchanged)))))
140 147
141;;;###autoload 148;;;###autoload