From ad6ad1646d7b3e9fac8198dc734d500ae0d40d78 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 11 Jul 2021 17:41:33 +0200 Subject: [PATCH] Use `auto-save-file-name-p' in tramp-*-write-region * lisp/net/tramp.el (tramp-handle-write-region): * lisp/net/tramp-adb.el (tramp-adb-handle-write-region): * lisp/net/tramp-sh.el (tramp-sh-handle-write-region): * lisp/net/tramp-smb.el (tramp-smb-handle-write-region): * lisp/net/tramp-sshfs.el (tramp-sshfs-handle-write-region): Use `auto-save-file-name-p'. --- lisp/net/tramp-adb.el | 11 +++++------ lisp/net/tramp-sh.el | 19 +++++++------------ lisp/net/tramp-smb.el | 7 +++---- lisp/net/tramp-sshfs.el | 7 +++---- lisp/net/tramp.el | 7 +++---- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 788548badec..63fd5eb06a3 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -549,14 +549,13 @@ But handle the case, if the \"test\" command is not available." (format "File %s exists; overwrite anyway? " filename))))) (tramp-error v 'file-already-exists filename)) - (let* ((auto-saving - (string-match-p "^#.+#$" (file-name-nondirectory filename))) - file-locked - (curbuf (current-buffer)) - (tmpfile (tramp-compat-make-temp-file filename))) + (let (file-locked + (curbuf (current-buffer)) + (tmpfile (tramp-compat-make-temp-file filename))) ;; Lock file. - (when (and (not auto-saving) (file-remote-p lockname) + (when (and (not (auto-save-file-name-p (file-name-nondirectory filename))) + (file-remote-p lockname) (not (eq (file-locked-p lockname) t))) (setq file-locked t) ;; `lock-file' exists since Emacs 28.1. diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 404e9aff7a2..e5929bd366a 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -3249,9 +3249,7 @@ implementation will be used." (format "File %s exists; overwrite anyway? " filename))))) (tramp-error v 'file-already-exists filename)) - (let ((auto-saving - (string-match-p "^#.+#$" (file-name-nondirectory filename))) - file-locked + (let (file-locked (uid (or (tramp-compat-file-attribute-user-id (file-attributes filename 'integer)) (tramp-get-remote-uid v 'integer))) @@ -3260,7 +3258,8 @@ implementation will be used." (tramp-get-remote-gid v 'integer)))) ;; Lock file. - (when (and (not auto-saving) (file-remote-p lockname) + (when (and (not (auto-save-file-name-p (file-name-nondirectory filename))) + (file-remote-p lockname) (not (eq (file-locked-p lockname) t))) (setq file-locked t) ;; `lock-file' exists since Emacs 28.1. @@ -3269,15 +3268,11 @@ implementation will be used." (if (and (tramp-local-host-p v) ;; `file-writable-p' calls `file-expand-file-name'. We ;; cannot use `tramp-run-real-handler' therefore. - (let (file-name-handler-alist) - (and - (file-writable-p (file-name-directory localname)) - (or (file-directory-p localname) - (file-writable-p localname))))) + (file-writable-p (file-name-directory localname)) + (or (file-directory-p localname) + (file-writable-p localname))) ;; Short track: if we are on the local host, we can run directly. - (write-region - start end localname append 'no-message - (and lockname (file-local-name lockname))) + (write-region start end localname append 'no-message lockname) (let* ((modes (tramp-default-file-modes filename (and (eq mustbenew 'excl) 'nofollow))) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 87f62391e34..d3de0455dd0 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -1589,14 +1589,13 @@ errors for shares like \"C$/\", which are common in Microsoft Windows." (format "File %s exists; overwrite anyway? " filename))))) (tramp-error v 'file-already-exists filename)) - (let ((auto-saving - (string-match-p "^#.+#$" (file-name-nondirectory filename))) - file-locked + (let (file-locked (curbuf (current-buffer)) (tmpfile (tramp-compat-make-temp-file filename))) ;; Lock file. - (when (and (not auto-saving) (file-remote-p lockname) + (when (and (not (auto-save-file-name-p (file-name-nondirectory filename))) + (file-remote-p lockname) (not (eq (file-locked-p lockname) t))) (setq file-locked t) ;; `lock-file' exists since Emacs 28.1. diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el index 3a3703b267d..f4872cef10c 100644 --- a/lisp/net/tramp-sshfs.el +++ b/lisp/net/tramp-sshfs.el @@ -295,12 +295,11 @@ arguments to pass to the OPERATION." (format "File %s exists; overwrite anyway? " filename))))) (tramp-error v 'file-already-exists filename)) - (let ((auto-saving - (string-match-p "^#.+#$" (file-name-nondirectory filename))) - file-locked) + (let (file-locked) ;; Lock file. - (when (and (not auto-saving) (file-remote-p lockname) + (when (and (not (auto-save-file-name-p (file-name-nondirectory filename))) + (file-remote-p lockname) (not (eq (file-locked-p lockname) t))) (setq file-locked t) ;; `lock-file' exists since Emacs 28.1. diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index fc714c9339a..9e6bfceb49a 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4438,9 +4438,7 @@ of." (format "File %s exists; overwrite anyway? " filename))))) (tramp-error v 'file-already-exists filename)) - (let ((auto-saving - (string-match-p "^#.+#$" (file-name-nondirectory filename))) - file-locked + (let (file-locked (tmpfile (tramp-compat-make-temp-file filename)) (modes (tramp-default-file-modes filename (and (eq mustbenew 'excl) 'nofollow))) @@ -4452,7 +4450,8 @@ of." (tramp-get-remote-gid v 'integer)))) ;; Lock file. - (when (and (not auto-saving) (file-remote-p lockname) + (when (and (not (auto-save-file-name-p (file-name-nondirectory filename))) + (file-remote-p lockname) (not (eq (file-locked-p lockname) t))) (setq file-locked t) ;; `lock-file' exists since Emacs 28.1. -- 2.39.2