Subject: bug#62614: Tramp attempts to remove lock file with 'remote-file-name-inhibit-locks t

From: Michael Albinus <[email-masked]>
Date: Mon, 03 Apr 2023 18:32:25 +0200

Yuri D'Elia <[email-masked]> writes:

Hi Yuri & Eli,

> On Mon, Apr 03 2023, Michael Albinus wrote:
>>> IMHO if lock creation is inhibited, we could still attempt to remove the
>>> lock to keep the old behavior, but then the warning shouldn't be
>>> generated as you don't expect the lock to exist in the normal case.
>>
>> That might be an option. But it wouldn't fix your use case, where you
>> try to avoid the file locking machinery for remote files at all.
>
> No, but it would fix an unexpected warning for both tramp and local
> files, which I think is beneficial.
>
> On Mon, Apr 03 2023, Eli Zaretskii wrote:
>> How about trying to remove the lock file, but if creation of lock
>> files is disabled, suppressing the warning?
>
> As above.

See appended patch. Shall it go to the emacs-29 or master branch?

Best regards, Michael.

diff --git a/lisp/files.el b/lisp/files.el
index d325729bf4d..216d31c737b 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -555,7 +555,7 @@ lock-file-name-transforms
   :version "28.1")

 (defcustom remote-file-name-inhibit-locks nil
-  "Whether to use file locks for remote files."
+  "Whether to create file locks for remote files."
   :group 'files
   :version "28.1"
   :type 'boolean)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index df2f0850b83..4180a32b6d9 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4585,7 +4585,8 @@ tramp-handle-unlock-file
     (condition-case err
         (delete-file lockname)
       ;; `userlock--handle-unlock-error' exists since Emacs 28.1.
-      (error (tramp-compat-funcall 'userlock--handle-unlock-error err)))))
+      (error (and (not (bound-and-true-p remote-file-name-inhibit-locks))
+                  (tramp-compat-funcall 'userlock--handle-unlock-error err))))))

 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
   "Like `load' for Tramp files."
diff --git a/lisp/userlock.el b/lisp/userlock.el
index 61f061d3e54..562bc0a0a9f 100644
--- a/lisp/userlock.el
+++ b/lisp/userlock.el
@@ -206,11 +206,12 @@ ask-user-about-supersession-help
 ;;;###autoload
 (defun userlock--handle-unlock-error (error)
   "Report an ERROR that occurred while unlocking a file."
-  (display-warning
-   '(unlock-file)
-   ;; There is no need to explain that this is an unlock error because
-   ;; ERROR is a `file-error' condition, which explains this.
-   (message "%s, ignored" (error-message-string error))
-   :warning))
+  (when create-lockfiles
+    (display-warning
+     '(unlock-file)
+     ;; There is no need to explain that this is an unlock error because
+     ;; ERROR is a `file-error' condition, which explains this.
+     (message "%s, ignored" (error-message-string error))
+     :warning)))

 ;;; userlock.el ends here