summaryrefslogtreecommitdiff
path: root/lisp/net/tramp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/net/tramp.el')
-rw-r--r--lisp/net/tramp.el60
1 files changed, 31 insertions, 29 deletions
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."