diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2021-07-09 18:14:19 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2021-07-09 18:14:19 +0200 |
commit | 9ce6541ac9710933beca7f9944087fe4849d5ae9 (patch) | |
tree | 133344956b38933f504071bfa114fc712296f43c /lisp | |
parent | 2870a72d0d6675e189457394ac421bd8e5ab4561 (diff) | |
download | emacs-9ce6541ac9710933beca7f9944087fe4849d5ae9.tar.gz emacs-9ce6541ac9710933beca7f9944087fe4849d5ae9.tar.bz2 emacs-9ce6541ac9710933beca7f9944087fe4849d5ae9.zip |
Further cleanup for file locks
* doc/misc/tramp.texi (Top, Configuration): Adapt node name for
file locks.
(Auto-save File Lock and Backup): Rename node name and section
title. Add file-lock to @cindex. Describe file locks.
* lisp/dired.el (dired-trivial-filenames): Add lock files.
(dired-font-lock-keywords): Move files suffixed with
`completion-ignored-extensions' up. Add lock files to these checks.
* lisp/net/tramp.el (tramp-get-lock-file, tramp-handle-unlock-file):
Use `when-let'
(tramp-lock-file-info-regexp): Rename from
`tramp-lock-file-contents-regexp'.
(tramp-handle-file-locked-p, tramp-handle-lock-file): Adapt callees.
(tramp-handle-lock-file): Set file modes of lockname.
* src/buffer.c (Frestore_buffer_modified_p):
* src/fileio.c (write_region):
* src/insdel.c (prepare_to_modify_buffer_1): Call Flock_file.
* src/filelock.c (Qmake_lock_file_name): Declare symbol.
(make_lock_file_name): Use it. Don't check Fboundp, it doesn't
work for interned symbols.
(lock_file): Return a Lisp_Object. Don't check create_lockfiles.
Remove MSDOS version of the function.
(Flock_file): Check create_lockfiles.
(Flock_buffer): Call Flock_file.
* src/lisp.h (lock_file): Remove.
* test/lisp/shadowfile-tests.el (shadow-test08-shadow-todo)
(shadow-test09-shadow-copy-files): Let-bind `create-lockfiles'.
* test/lisp/net/tramp-tests.el (create-lockfiles): Don't set it
globally.
(tramp-test39-lock-file): Check also for `set-visited-file-name'.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/dired.el | 50 | ||||
-rw-r--r-- | lisp/net/tramp.el | 60 |
2 files changed, 57 insertions, 53 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index 9ddd2c542dc..fb353a92e45 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -163,7 +163,7 @@ always set this variable to t." :type 'boolean :group 'dired-mark) -(defcustom dired-trivial-filenames (purecopy "\\`\\.\\.?\\'\\|\\`#") +(defcustom dired-trivial-filenames (purecopy "\\`\\.\\.?\\'\\|\\`\\.?#") "Regexp of files to skip when finding first file of a directory. A value of nil means move to the subdir line. A value of t means move to first file." @@ -615,6 +615,31 @@ Subexpression 2 must end right before the \\n.") (list dired-re-dir '(".+" (dired-move-to-filename) nil (0 dired-directory-face))) ;; + ;; Files suffixed with `completion-ignored-extensions'. + '(eval . + ;; It is quicker to first find just an extension, then go back to the + ;; start of that file name. So we do this complex MATCH-ANCHORED form. + (list (concat + "\\(" (regexp-opt completion-ignored-extensions) + "\\|#\\|\\.#.+\\)$") + '(".+" (dired-move-to-filename) nil (0 dired-ignored-face)))) + ;; + ;; Files suffixed with `completion-ignored-extensions' + ;; plus a character put in by -F. + '(eval . + (list (concat "\\(" (regexp-opt completion-ignored-extensions) + "\\|#\\|\\.#.+\\)[*=|]$") + '(".+" (progn + (end-of-line) + ;; If the last character is not part of the filename, + ;; move back to the start of the filename + ;; so it can be fontified. + ;; Otherwise, leave point at the end of the line; + ;; that way, nothing is fontified. + (unless (get-text-property (1- (point)) 'mouse-face) + (dired-move-to-filename))) + nil (0 dired-ignored-face)))) + ;; ;; Broken Symbolic link. (list dired-re-sym (list (lambda (end) @@ -659,29 +684,6 @@ Subexpression 2 must end right before the \\n.") (list dired-re-special '(".+" (dired-move-to-filename) nil (0 'dired-special))) ;; - ;; Files suffixed with `completion-ignored-extensions'. - '(eval . - ;; It is quicker to first find just an extension, then go back to the - ;; start of that file name. So we do this complex MATCH-ANCHORED form. - (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$") - '(".+" (dired-move-to-filename) nil (0 dired-ignored-face)))) - ;; - ;; Files suffixed with `completion-ignored-extensions' - ;; plus a character put in by -F. - '(eval . - (list (concat "\\(" (regexp-opt completion-ignored-extensions) - "\\|#\\)[*=|]$") - '(".+" (progn - (end-of-line) - ;; If the last character is not part of the filename, - ;; move back to the start of the filename - ;; so it can be fontified. - ;; Otherwise, leave point at the end of the line; - ;; that way, nothing is fontified. - (unless (get-text-property (1- (point)) 'mouse-face) - (dired-move-to-filename))) - nil (0 dired-ignored-face)))) - ;; ;; Explicitly put the default face on file names ending in a colon to ;; avoid fontifying them as directory header. (list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms ".*:$") diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 7578d6fe308..fc714c9339a 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3819,9 +3819,9 @@ User is always nil." (cons (expand-file-name filename) (cdr result))))) (defun tramp-get-lock-file (file) - "Read lockfile of FILE. -Return nil when there is no lockfile" - (let ((lockname (tramp-compat-make-lock-file-name file))) + "Read lockfile info of FILE. +Return nil when there is no lockfile." + (when-let ((lockname (tramp-compat-make-lock-file-name file))) (or (file-symlink-p lockname) (and (file-readable-p lockname) (with-temp-buffer @@ -3839,51 +3839,53 @@ Return nil when there is no lockfile" (or (process-id p) (tramp-get-connection-property p "lock-pid" (emacs-pid)))))) -(defconst tramp-lock-file-contents-regexp +(defconst tramp-lock-file-info-regexp ;; USER@HOST.PID[:BOOT_TIME] "\\`\\(.+\\)@\\(.+\\)\\.\\([[:digit:]]+\\)\\(?::\\([[:digit:]]+\\)\\)?\\'" "The format of a lock file.") (defun tramp-handle-file-locked-p (file) "Like `file-locked-p' for Tramp files." - (when-let ((contents (tramp-get-lock-file file)) - (match (string-match tramp-lock-file-contents-regexp contents))) - (or (and (string-equal (match-string 1 contents) (user-login-name)) - (string-equal (match-string 2 contents) (system-name)) - (string-equal (match-string 3 contents) (tramp-get-lock-pid file))) - (match-string 1 contents)))) + (when-let ((info (tramp-get-lock-file file)) + (match (string-match tramp-lock-file-info-regexp info))) + (or (and (string-equal (match-string 1 info) (user-login-name)) + (string-equal (match-string 2 info) (system-name)) + (string-equal (match-string 3 info) (tramp-get-lock-pid file))) + (match-string 1 info)))) (defun tramp-handle-lock-file (file) "Like `lock-file' for Tramp files." ;; See if this file is visited and has changed on disk since it ;; was visited. (catch 'dont-lock - (unless (or (null create-lockfiles) - (eq (file-locked-p file) t)) ;; Locked by me. - (when-let ((contents (tramp-get-lock-file file)) - (match (string-match tramp-lock-file-contents-regexp contents))) + (unless (eq (file-locked-p file) t) ;; Locked by me. + (when-let ((info (tramp-get-lock-file file)) + (match (string-match tramp-lock-file-info-regexp info))) (unless (ask-user-about-lock file (format - "%s@%s (pid %s)" (match-string 1 contents) - (match-string 2 contents) (match-string 3 contents))) + "%s@%s (pid %s)" (match-string 1 info) + (match-string 2 info) (match-string 3 info))) (throw 'dont-lock nil))) - (let ((lockname (tramp-compat-make-lock-file-name file)) - ;; USER@HOST.PID[:BOOT_TIME] - (contents - (format - "%s@%s.%s" (user-login-name) (system-name) - (tramp-get-lock-pid file))) - create-lockfiles signal-hook-function) - (condition-case nil - (make-symbolic-link contents lockname 'ok-if-already-exists) - (error (write-region contents nil lockname))))))) + (when-let ((lockname (tramp-compat-make-lock-file-name file)) + ;; USER@HOST.PID[:BOOT_TIME] + (info + (format + "%s@%s.%s" (user-login-name) (system-name) + (tramp-get-lock-pid file)))) + (let (create-lockfiles signal-hook-function) + (condition-case nil + (make-symbolic-link info lockname 'ok-if-already-exists) + (error + (write-region info nil lockname) + (set-file-modes lockname #o0644)))))))) (defun tramp-handle-unlock-file (file) "Like `unlock-file' for Tramp files." - (condition-case err - (delete-file (tramp-compat-make-lock-file-name file)) - (error (userlock--handle-unlock-error err)))) + (when-let ((lockname (tramp-compat-make-lock-file-name file))) + (condition-case err + (delete-file lockname) + (error (userlock--handle-unlock-error err))))) (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix) "Like `load' for Tramp files." |