From: Eli Zaretskii Date: Mon, 24 Jul 2023 15:08:40 +0000 (+0300) Subject: Don't signal error when locking a file from non file-visiting buffer X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=89558533683a100ca7946c4a35bf4ef50463efef;p=emacs.git 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) --- 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.")) (defun userlock--check-content-unchanged (filename) (with-demoted-errors "Unchanged content check: %S" - ;; Even tho we receive `filename', we know that `filename' refers to the current - ;; buffer's file. - (cl-assert (equal (expand-file-name filename) - (expand-file-name buffer-file-truename))) + ;; Even tho we receive `filename', we know that `filename' refers + ;; to the current buffer's file. + (cl-assert (or (null buffer-file-truename) ; temporary buffer + (equal (expand-file-name filename) + (expand-file-name buffer-file-truename)))) ;; Note: rather than read the file and compare to the buffer, we could save ;; the buffer and compare to the file, but for encrypted data this ;; wouldn't work well (and would risk exposing the data). @@ -135,7 +136,13 @@ You can <\\`q'>uit; don't modify this file.")) (compare-buffer-substrings buf start end (current-buffer) (point-min) (point-max)))))) - (set-visited-file-modtime) + ;; We know that some buffer visits FILENAME, because our + ;; caller (see lock_file) verified that. Thus, we set the + ;; modtime in that buffer, to cater to use case where the + ;; file is about to be written to from some buffer that + ;; doesn't visit any file, like a temporary buffer. + (with-current-buffer (get-file-buffer (file-truename filename)) + (set-visited-file-modtime)) 'unchanged))))) ;;;###autoload