diff options
| author | Michael Albinus | 2021-07-13 19:50:05 +0200 |
|---|---|---|
| committer | Michael Albinus | 2021-07-13 19:50:05 +0200 |
| commit | cce84822f72e6cd4af7bfa351a4da2c9bdc5bb81 (patch) | |
| tree | a200828f55384268354d7fbb972e98765d111ca2 | |
| parent | 7a803ecd3d455999cfc9266fa219d58109fac786 (diff) | |
| download | emacs-cce84822f72e6cd4af7bfa351a4da2c9bdc5bb81.tar.gz emacs-cce84822f72e6cd4af7bfa351a4da2c9bdc5bb81.zip | |
Add remote-file-name-inhibit-locks
* doc/emacs/files.texi (Interlocking):
* doc/lispref/files.texi (File Locks):
* doc/misc/tramp.texi (Auto-save File Lock and Backup):
Add remote-file-name-inhibit-locks.
* etc/NEWS: New user option 'remote-file-name-inhibit-locks'.
* lisp/files.el (remote-file-name-inhibit-locks): New defcustom.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Use `tramp-handle-make-lock-file-name'.
* lisp/net/tramp.el (tramp-allow-unsafe-temporary-files): Fix docstring.
(tramp-handle-make-lock-file-name): New defun.
* test/lisp/net/tramp-tests.el (tramp-test39-lock-file): Extend test.
| -rw-r--r-- | doc/emacs/files.texi | 4 | ||||
| -rw-r--r-- | doc/lispref/files.texi | 5 | ||||
| -rw-r--r-- | doc/misc/tramp.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 15 | ||||
| -rw-r--r-- | lisp/files.el | 6 | ||||
| -rw-r--r-- | lisp/net/tramp-adb.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-crypt.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-rclone.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-smb.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sshfs.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sudoedit.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 26 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 64 |
15 files changed, 110 insertions, 36 deletions
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 98b6b194d2d..32a2f1bb815 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi | |||
| @@ -836,6 +836,10 @@ warning message and asks for confirmation before saving; answer | |||
| 836 | place, one way to compare the buffer to its file is the @kbd{M-x | 836 | place, one way to compare the buffer to its file is the @kbd{M-x |
| 837 | diff-buffer-with-file} command. @xref{Comparing Files}. | 837 | diff-buffer-with-file} command. @xref{Comparing Files}. |
| 838 | 838 | ||
| 839 | @vindex remote-file-name-inhibit-locks | ||
| 840 | You can prevent the creation of remote lock files by setting the | ||
| 841 | variable @code{remote-file-name-inhibit-locks} to @code{t}. | ||
| 842 | |||
| 839 | @node File Shadowing | 843 | @node File Shadowing |
| 840 | @subsection Shadowing Files | 844 | @subsection Shadowing Files |
| 841 | @cindex shadow files | 845 | @cindex shadow files |
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index b1b70a9f063..1f4049f715c 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -821,6 +821,11 @@ If you wish, you can replace the @code{ask-user-about-lock} function | |||
| 821 | with your own version that makes the decision in another way. | 821 | with your own version that makes the decision in another way. |
| 822 | @end defun | 822 | @end defun |
| 823 | 823 | ||
| 824 | @defopt remote-file-name-inhibit-locks | ||
| 825 | You can prevent the creation of remote lock files by setting the | ||
| 826 | variable @code{remote-file-name-inhibit-locks} to @code{t}. | ||
| 827 | @end defopt | ||
| 828 | |||
| 824 | @node Information about Files | 829 | @node Information about Files |
| 825 | @section Information about Files | 830 | @section Information about Files |
| 826 | @cindex file, information about | 831 | @cindex file, information about |
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 8ba5f0118a3..088352e8a8a 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi | |||
| @@ -2858,11 +2858,15 @@ to warn you, if a file is changed in parallel from different Emacs | |||
| 2858 | sessions, or via different remote connections. Be careful with such | 2858 | sessions, or via different remote connections. Be careful with such |
| 2859 | settings. | 2859 | settings. |
| 2860 | 2860 | ||
| 2861 | @vindex remote-file-name-inhibit-locks | ||
| 2862 | Setting @code{remote-file-name-inhibit-locks} to non-@code{nil} | ||
| 2863 | prevents the creation of remote lock files at all. | ||
| 2864 | |||
| 2861 | @vindex tramp-allow-unsafe-temporary-files | 2865 | @vindex tramp-allow-unsafe-temporary-files |
| 2862 | Per default, @value{tramp} asks for confirmation if a | 2866 | Per default, @value{tramp} asks for confirmation if a |
| 2863 | @samp{root}-owned backup or auto-save remote file has to be written to | 2867 | @samp{root}-owned remote backup, auto-save or lock file has to be |
| 2864 | your local temporary directory. If you want to suppress this | 2868 | written to your local temporary directory. If you want to suppress |
| 2865 | confirmation question, set user option | 2869 | this confirmation question, set user option |
| 2866 | @code{tramp-allow-unsafe-temporary-files} to @code{t}. | 2870 | @code{tramp-allow-unsafe-temporary-files} to @code{t}. |
| 2867 | 2871 | ||
| 2868 | 2872 | ||
| @@ -1464,12 +1464,15 @@ buffer to a file under the "/tmp/" directory. This is useful, if (in | |||
| 1464 | rare cases) Tramp blocks Emacs, and we need further debug information. | 1464 | rare cases) Tramp blocks Emacs, and we need further debug information. |
| 1465 | 1465 | ||
| 1466 | +++ | 1466 | +++ |
| 1467 | *** Writing sensitive auto-save or backup files to the local temporary | 1467 | *** Tramp supports lock files now. |
| 1468 | directory must be confirmed. In order to suppress this confirmation, | 1468 | In order to deactivate this, set user option |
| 1469 | set user option 'tramp-allow-unsafe-temporary-files' to t. | 1469 | 'remote-file-name-inhibit-locks' to t. |
| 1470 | 1470 | ||
| 1471 | +++ | 1471 | +++ |
| 1472 | *** Tramp supports file locks now. | 1472 | *** Writing sensitive auto-save, backup or lock files to the local |
| 1473 | temporary directory must be confirmed. In order to suppress this | ||
| 1474 | confirmation, set user option 'tramp-allow-unsafe-temporary-files' to | ||
| 1475 | t. | ||
| 1473 | 1476 | ||
| 1474 | ** Tempo | 1477 | ** Tempo |
| 1475 | 1478 | ||
| @@ -2183,6 +2186,10 @@ This option allows controlling where lock files are written. It uses | |||
| 2183 | the same syntax as 'auto-save-file-name-transforms'. | 2186 | the same syntax as 'auto-save-file-name-transforms'. |
| 2184 | 2187 | ||
| 2185 | +++ | 2188 | +++ |
| 2189 | *** New user option 'remote-file-name-inhibit-locks'. | ||
| 2190 | When non-nil, this option suppresses lock files for remote files. | ||
| 2191 | |||
| 2192 | +++ | ||
| 2186 | *** New user option 'kill-transform-function'. | 2193 | *** New user option 'kill-transform-function'. |
| 2187 | This can be used to transform (and suppress) strings from entering the | 2194 | This can be used to transform (and suppress) strings from entering the |
| 2188 | kill ring. | 2195 | kill ring. |
diff --git a/lisp/files.el b/lisp/files.el index 0dfcab8f89b..ad02d373fd0 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -427,6 +427,12 @@ file it's locking, and it has the same name, but with \".#\" prepended." | |||
| 427 | :initialize 'custom-initialize-delay | 427 | :initialize 'custom-initialize-delay |
| 428 | :version "28.1") | 428 | :version "28.1") |
| 429 | 429 | ||
| 430 | (defcustom remote-file-name-inhibit-locks nil | ||
| 431 | "Whether to use file locks for remote files." | ||
| 432 | :group 'files | ||
| 433 | :version "28.1" | ||
| 434 | :type 'boolean) | ||
| 435 | |||
| 430 | (defvar auto-save--timer nil "Timer for `auto-save-visited-mode'.") | 436 | (defvar auto-save--timer nil "Timer for `auto-save-visited-mode'.") |
| 431 | 437 | ||
| 432 | (defcustom auto-save-visited-interval 5 | 438 | (defcustom auto-save-visited-interval 5 |
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index dbbbfe6a3f9..8138d9a3608 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -164,7 +164,7 @@ It is used for TCP/IP devices." | |||
| 164 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 164 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 165 | (make-directory . tramp-adb-handle-make-directory) | 165 | (make-directory . tramp-adb-handle-make-directory) |
| 166 | (make-directory-internal . ignore) | 166 | (make-directory-internal . ignore) |
| 167 | ;; `make-lock-file-name' performed by default handler. | 167 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 168 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 168 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 169 | (make-process . tramp-adb-handle-make-process) | 169 | (make-process . tramp-adb-handle-make-process) |
| 170 | (make-symbolic-link . tramp-handle-make-symbolic-link) | 170 | (make-symbolic-link . tramp-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el index 1b77fea7e18..109db3b1d7b 100644 --- a/lisp/net/tramp-crypt.el +++ b/lisp/net/tramp-crypt.el | |||
| @@ -213,7 +213,7 @@ If NAME doesn't belong to a crypted remote directory, retun nil." | |||
| 213 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 213 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 214 | (make-directory . tramp-crypt-handle-make-directory) | 214 | (make-directory . tramp-crypt-handle-make-directory) |
| 215 | (make-directory-internal . ignore) | 215 | (make-directory-internal . ignore) |
| 216 | ;; `make-lock-file-name' performed by default handler. | 216 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 217 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 217 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 218 | (make-process . ignore) | 218 | (make-process . ignore) |
| 219 | (make-symbolic-link . tramp-handle-make-symbolic-link) | 219 | (make-symbolic-link . tramp-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 04de5defb37..022fdeeb885 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el | |||
| @@ -805,7 +805,7 @@ It has been changed in GVFS 1.14.") | |||
| 805 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 805 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 806 | (make-directory . tramp-gvfs-handle-make-directory) | 806 | (make-directory . tramp-gvfs-handle-make-directory) |
| 807 | (make-directory-internal . ignore) | 807 | (make-directory-internal . ignore) |
| 808 | ;; `make-lock-file-name' performed by default handler. | 808 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 809 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 809 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 810 | (make-process . ignore) | 810 | (make-process . ignore) |
| 811 | (make-symbolic-link . tramp-handle-make-symbolic-link) | 811 | (make-symbolic-link . tramp-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index 473fa8a8f0e..49e366c01c6 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el | |||
| @@ -127,7 +127,7 @@ | |||
| 127 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 127 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 128 | (make-directory . tramp-fuse-handle-make-directory) | 128 | (make-directory . tramp-fuse-handle-make-directory) |
| 129 | (make-directory-internal . ignore) | 129 | (make-directory-internal . ignore) |
| 130 | ;; `make-lock-file-name' performed by default handler. | 130 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 131 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 131 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 132 | (make-process . ignore) | 132 | (make-process . ignore) |
| 133 | (make-symbolic-link . tramp-handle-make-symbolic-link) | 133 | (make-symbolic-link . tramp-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 3595bd26557..760320d7ed4 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -993,7 +993,7 @@ Format specifiers \"%s\" are replaced before the script is used.") | |||
| 993 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 993 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 994 | (make-directory . tramp-sh-handle-make-directory) | 994 | (make-directory . tramp-sh-handle-make-directory) |
| 995 | ;; `make-directory-internal' performed by default handler. | 995 | ;; `make-directory-internal' performed by default handler. |
| 996 | ;; `make-lock-file-name' performed by default handler. | 996 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 997 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 997 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 998 | (make-process . tramp-sh-handle-make-process) | 998 | (make-process . tramp-sh-handle-make-process) |
| 999 | (make-symbolic-link . tramp-sh-handle-make-symbolic-link) | 999 | (make-symbolic-link . tramp-sh-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 1c7ddee0086..4008c25d3af 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el | |||
| @@ -278,7 +278,7 @@ See `tramp-actions-before-shell' for more info.") | |||
| 278 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 278 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 279 | (make-directory . tramp-smb-handle-make-directory) | 279 | (make-directory . tramp-smb-handle-make-directory) |
| 280 | (make-directory-internal . tramp-smb-handle-make-directory-internal) | 280 | (make-directory-internal . tramp-smb-handle-make-directory-internal) |
| 281 | ;; `make-lock-file-name' performed by default handler. | 281 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 282 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 282 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 283 | (make-process . ignore) | 283 | (make-process . ignore) |
| 284 | (make-symbolic-link . tramp-smb-handle-make-symbolic-link) | 284 | (make-symbolic-link . tramp-smb-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el index 5f6807a0db7..99f4063988f 100644 --- a/lisp/net/tramp-sshfs.el +++ b/lisp/net/tramp-sshfs.el | |||
| @@ -127,7 +127,7 @@ | |||
| 127 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 127 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 128 | (make-directory . tramp-fuse-handle-make-directory) | 128 | (make-directory . tramp-fuse-handle-make-directory) |
| 129 | (make-directory-internal . ignore) | 129 | (make-directory-internal . ignore) |
| 130 | ;; `make-lock-file-name' performed by default handler. | 130 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 131 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 131 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 132 | (make-process . tramp-handle-make-process) | 132 | (make-process . tramp-handle-make-process) |
| 133 | (make-symbolic-link . tramp-handle-make-symbolic-link) | 133 | (make-symbolic-link . tramp-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index d68a5c1adf4..45d9fab986c 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el | |||
| @@ -120,7 +120,7 @@ See `tramp-actions-before-shell' for more info.") | |||
| 120 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) | 120 | (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) |
| 121 | (make-directory . tramp-sudoedit-handle-make-directory) | 121 | (make-directory . tramp-sudoedit-handle-make-directory) |
| 122 | (make-directory-internal . ignore) | 122 | (make-directory-internal . ignore) |
| 123 | ;; `make-lock-file-name' performed by default handler. | 123 | (make-lock-file-name . tramp-handle-make-lock-file-name) |
| 124 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) | 124 | (make-nearby-temp-file . tramp-handle-make-nearby-temp-file) |
| 125 | (make-process . ignore) | 125 | (make-process . ignore) |
| 126 | (make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link) | 126 | (make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link) |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 9e6bfceb49a..3f586c62170 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -3630,7 +3630,7 @@ User is always nil." | |||
| 3630 | (file-writable-p (file-name-directory filename))))))) | 3630 | (file-writable-p (file-name-directory filename))))))) |
| 3631 | 3631 | ||
| 3632 | (defcustom tramp-allow-unsafe-temporary-files nil | 3632 | (defcustom tramp-allow-unsafe-temporary-files nil |
| 3633 | "Whether root-owned auto-save or backup files can be written to \"/tmp\"." | 3633 | "Whether root-owned auto-save, backup or lock files can be written to \"/tmp\"." |
| 3634 | :version "28.1" | 3634 | :version "28.1" |
| 3635 | :type 'boolean) | 3635 | :type 'boolean) |
| 3636 | 3636 | ||
| @@ -3880,6 +3880,30 @@ Return nil when there is no lockfile." | |||
| 3880 | (write-region info nil lockname) | 3880 | (write-region info nil lockname) |
| 3881 | (set-file-modes lockname #o0644)))))))) | 3881 | (set-file-modes lockname #o0644)))))))) |
| 3882 | 3882 | ||
| 3883 | (defun tramp-handle-make-lock-file-name (file) | ||
| 3884 | "Like `make-lock-file-name' for Tramp files." | ||
| 3885 | (when (and create-lockfiles | ||
| 3886 | ;; This variable has been introduced with Emacs 28.1. | ||
| 3887 | (not (bound-and-true-p remote-file-name-inhibit-locks))) | ||
| 3888 | (with-parsed-tramp-file-name file nil | ||
| 3889 | (let ((result | ||
| 3890 | ;; Run plain `make-lock-file-name'. | ||
| 3891 | (tramp-run-real-handler #'make-lock-file-name (list file)))) | ||
| 3892 | ;; Protect against security hole. | ||
| 3893 | (when (and (not tramp-allow-unsafe-temporary-files) | ||
| 3894 | (file-in-directory-p result temporary-file-directory) | ||
| 3895 | (zerop (or (tramp-compat-file-attribute-user-id | ||
| 3896 | (file-attributes file 'integer)) | ||
| 3897 | tramp-unknown-id-integer)) | ||
| 3898 | (not (with-tramp-connection-property | ||
| 3899 | (tramp-get-process v) "unsafe-temporary-file" | ||
| 3900 | (yes-or-no-p | ||
| 3901 | (concat | ||
| 3902 | "Lock file on local temporary directory, " | ||
| 3903 | "do you want to continue? "))))) | ||
| 3904 | (tramp-error v 'file-error "Unsafe lock file name")) | ||
| 3905 | result)))) | ||
| 3906 | |||
| 3883 | (defun tramp-handle-unlock-file (file) | 3907 | (defun tramp-handle-unlock-file (file) |
| 3884 | "Like `unlock-file' for Tramp files." | 3908 | "Like `unlock-file' for Tramp files." |
| 3885 | (when-let ((lockname (tramp-compat-make-lock-file-name file))) | 3909 | (when-let ((lockname (tramp-compat-make-lock-file-name file))) |
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 44fd1b45b26..bc05db8095b 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -5751,8 +5751,10 @@ Use direct async.") | |||
| 5751 | (skip-unless (and (fboundp 'lock-file) (fboundp 'unlock-file))) | 5751 | (skip-unless (and (fboundp 'lock-file) (fboundp 'unlock-file))) |
| 5752 | 5752 | ||
| 5753 | (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) | 5753 | (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) |
| 5754 | (let ((tmp-name (tramp--test-make-temp-name nil quoted)) | 5754 | (let ((tmp-name1 (tramp--test-make-temp-name nil quoted)) |
| 5755 | (tmp-name2 (tramp--test-make-temp-name nil quoted)) | ||
| 5755 | (remote-file-name-inhibit-cache t) | 5756 | (remote-file-name-inhibit-cache t) |
| 5757 | (remote-file-name-inhibit-locks nil) | ||
| 5756 | (create-lockfiles t) | 5758 | (create-lockfiles t) |
| 5757 | (inhibit-message t) | 5759 | (inhibit-message t) |
| 5758 | ;; tramp-rclone.el and tramp-sshfs.el cache the mounted files. | 5760 | ;; tramp-rclone.el and tramp-sshfs.el cache the mounted files. |
| @@ -5765,51 +5767,73 @@ Use direct async.") | |||
| 5765 | (unwind-protect | 5767 | (unwind-protect |
| 5766 | (progn | 5768 | (progn |
| 5767 | ;; A simple file lock. | 5769 | ;; A simple file lock. |
| 5768 | (should-not (file-locked-p tmp-name)) | 5770 | (should-not (file-locked-p tmp-name1)) |
| 5769 | (lock-file tmp-name) | 5771 | (lock-file tmp-name1) |
| 5770 | (should (eq (file-locked-p tmp-name) t)) | 5772 | (should (eq (file-locked-p tmp-name1) t)) |
| 5771 | 5773 | ||
| 5772 | ;; If it is locked already, nothing changes. | 5774 | ;; If it is locked already, nothing changes. |
| 5773 | (lock-file tmp-name) | 5775 | (lock-file tmp-name1) |
| 5774 | (should (eq (file-locked-p tmp-name) t)) | 5776 | (should (eq (file-locked-p tmp-name1) t)) |
| 5775 | 5777 | ||
| 5776 | ;; A new connection changes process id, and also the | 5778 | ;; A new connection changes process id, and also the |
| 5777 | ;; lockname contents. | 5779 | ;; lockname contents. |
| 5778 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) | 5780 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) |
| 5779 | (should (stringp (file-locked-p tmp-name))) | 5781 | (should (stringp (file-locked-p tmp-name1))) |
| 5782 | |||
| 5783 | ;; When `remote-file-name-inhibit-locks' is set, nothing happens. | ||
| 5784 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) | ||
| 5785 | (let ((remote-file-name-inhibit-locks t)) | ||
| 5786 | (lock-file tmp-name1) | ||
| 5787 | (should-not (file-locked-p tmp-name1))) | ||
| 5788 | |||
| 5789 | ;; When `lock-file-name-transforms' is set, another lock | ||
| 5790 | ;; file is used. | ||
| 5791 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) | ||
| 5792 | (let ((lock-file-name-transforms `((".*" ,tmp-name2)))) | ||
| 5793 | (should | ||
| 5794 | (string-equal | ||
| 5795 | (make-lock-file-name tmp-name1) | ||
| 5796 | (make-lock-file-name tmp-name2))) | ||
| 5797 | (lock-file tmp-name1) | ||
| 5798 | (should (eq (file-locked-p tmp-name1) t)) | ||
| 5799 | (unlock-file tmp-name1) | ||
| 5800 | (should-not (file-locked-p tmp-name1))) | ||
| 5780 | 5801 | ||
| 5781 | ;; Steal the file lock. | 5802 | ;; Steal the file lock. |
| 5782 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) | 5803 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) |
| 5783 | (cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?s))) | 5804 | (cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?s))) |
| 5784 | (lock-file tmp-name)) | 5805 | (lock-file tmp-name1)) |
| 5785 | (should (eq (file-locked-p tmp-name) t)) | 5806 | (should (eq (file-locked-p tmp-name1) t)) |
| 5786 | 5807 | ||
| 5787 | ;; Ignore the file lock. | 5808 | ;; Ignore the file lock. |
| 5788 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) | 5809 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) |
| 5789 | (cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?p))) | 5810 | (cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?p))) |
| 5790 | (lock-file tmp-name)) | 5811 | (lock-file tmp-name1)) |
| 5791 | (should (stringp (file-locked-p tmp-name))) | 5812 | (should (stringp (file-locked-p tmp-name1))) |
| 5792 | 5813 | ||
| 5793 | ;; Quit the file lock machinery. | 5814 | ;; Quit the file lock machinery. |
| 5794 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) | 5815 | (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) |
| 5795 | (cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?q))) | 5816 | (cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?q))) |
| 5796 | (should-error (lock-file tmp-name) :type 'file-locked) | 5817 | (should-error (lock-file tmp-name1) :type 'file-locked) |
| 5797 | ;; The same for `write-region'. | 5818 | ;; The same for `write-region'. |
| 5798 | (should-error (write-region "foo" nil tmp-name) :type 'file-locked) | ||
| 5799 | (should-error | 5819 | (should-error |
| 5800 | (write-region "foo" nil tmp-name nil nil tmp-name) | 5820 | (write-region "foo" nil tmp-name1) :type 'file-locked) |
| 5821 | (should-error | ||
| 5822 | (write-region "foo" nil tmp-name1 nil nil tmp-name1) | ||
| 5801 | :type 'file-locked) | 5823 | :type 'file-locked) |
| 5802 | ;; The same for `set-visited-file-name'. | 5824 | ;; The same for `set-visited-file-name'. |
| 5803 | (with-temp-buffer | 5825 | (with-temp-buffer |
| 5804 | (should-error | 5826 | (should-error |
| 5805 | (set-visited-file-name tmp-name) :type 'file-locked))) | 5827 | (set-visited-file-name tmp-name1) :type 'file-locked))) |
| 5806 | (should (stringp (file-locked-p tmp-name))) | 5828 | (should (stringp (file-locked-p tmp-name1))) |
| 5807 | (should-not (file-exists-p tmp-name))) | 5829 | (should-not (file-exists-p tmp-name1))) |
| 5808 | 5830 | ||
| 5809 | ;; Cleanup. | 5831 | ;; Cleanup. |
| 5810 | (ignore-errors (delete-file tmp-name)) | 5832 | (ignore-errors (delete-file tmp-name1)) |
| 5811 | (unlock-file tmp-name) | 5833 | (unlock-file tmp-name1) |
| 5812 | (should-not (file-locked-p tmp-name)))))) | 5834 | (unlock-file tmp-name2) |
| 5835 | (should-not (file-locked-p tmp-name1)) | ||
| 5836 | (should-not (file-locked-p tmp-name2)))))) | ||
| 5813 | 5837 | ||
| 5814 | ;; The functions were introduced in Emacs 26.1. | 5838 | ;; The functions were introduced in Emacs 26.1. |
| 5815 | (ert-deftest tramp-test40-make-nearby-temp-file () | 5839 | (ert-deftest tramp-test40-make-nearby-temp-file () |