emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 36b6124d810: Fix userlock.el and filelock-tests in some rare case


From: Eli Zaretskii
Subject: master 36b6124d810: Fix userlock.el and filelock-tests in some rare cases
Date: Fri, 28 Jul 2023 02:32:22 -0400 (EDT)

branch: master
commit 36b6124d810679cc0f23282d51d9bf8b01f26011
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Fix userlock.el and filelock-tests in some rare cases
    
    * lisp/userlock.el (userlock--check-content-unchanged): Don't
    assume 'file-truename' of FILENAME is always non-nil.  It could be
    nil if we are called from a temporary buffer where some Lisp
    program has forcibly set 'buffer-file-name'.  (Bug#64821)
    
    * test/src/filelock-tests.el (filelock-tests--fixture): Set
    'buffer-file-name' to the true name of the temporary file.
    Patch by Mattias EngdegÄrd <mattias.engdegard@gmail.com>.
    (filelock-tests-detect-external-change): Quote the file names
    passed to shell commands.
---
 lisp/userlock.el           |  6 ++++--
 test/src/filelock-tests.el | 14 ++++++++++----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lisp/userlock.el b/lisp/userlock.el
index 96de17d54fd..4623608f1db 100644
--- a/lisp/userlock.el
+++ b/lisp/userlock.el
@@ -141,8 +141,10 @@ You can <\\`q'>uit; don't modify this file."))
           ;; 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))
+          (let ((buf (get-file-buffer (file-truename filename))))
+            (when buf  ; If we cannot find the visiting buffer, punt.
+              (with-current-buffer buf
+                (set-visited-file-modtime))))
           'unchanged)))))
 
 ;;;###autoload
diff --git a/test/src/filelock-tests.el b/test/src/filelock-tests.el
index 1f055cfebc6..c5e77f70bb2 100644
--- a/test/src/filelock-tests.el
+++ b/test/src/filelock-tests.el
@@ -38,8 +38,12 @@ Create a test directory and a buffer whose 
`buffer-file-name' and
 Finally, delete the buffer and the test directory."
   (declare (debug (body)))
   `(ert-with-temp-directory temp-dir
-     (let ((name (concat (file-name-as-directory temp-dir)
-                         "userfile"))
+     (let ((name
+            ;; Use file-truename for when 'temporary-file-directory'
+            ;; is a symlink, to make sure 'buffer-file-name' is set
+            ;; below to a real existing file.
+            (file-truename (concat (file-name-as-directory temp-dir)
+                                   "userfile")))
            (create-lockfiles t))
        (with-temp-buffer
          (setq buffer-file-name name
@@ -184,7 +188,8 @@ the case)."
 
        ;; Just changing the file modification on disk doesn't hurt,
        ;; because file contents in buffer and on disk look equal.
-       (shell-command (format "touch %s" (buffer-file-name)))
+       (shell-command (format "touch %s"
+                              (shell-quote-argument (buffer-file-name))))
        (insert "bar")
        (when cl (filelock-tests--should-be-locked))
 
@@ -198,7 +203,8 @@ the case)."
        ;; Changing the file contents on disk hurts when buffer is
        ;; modified.  There shall be a query, which we answer.
        ;; *Messages* buffer is checked for prompt.
-       (shell-command (format "echo bar >>%s" (buffer-file-name)))
+       (shell-command (format "echo bar >>%s"
+                              (shell-quote-argument (buffer-file-name))))
        (cl-letf (((symbol-function 'read-char-choice)
                   (lambda (prompt &rest _) (message "%s" prompt) ?y)))
          (ert-with-message-capture captured-messages



reply via email to

[Prev in Thread] Current Thread [Next in Thread]