[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 16cb27d1d98 1/2: Optimize Tramp's copy-directory
From: |
Michael Albinus |
Subject: |
master 16cb27d1d98 1/2: Optimize Tramp's copy-directory |
Date: |
Sat, 24 Aug 2024 06:50:27 -0400 (EDT) |
branch: master
commit 16cb27d1d986d8b00ee1da2f7f51e8e6f254f173
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>
Optimize Tramp's copy-directory
* lisp/net/tramp-sh.el (tramp-sh-handle-copy-directory):
* lisp/net/tramp-smb.el (tramp-smb-handle-copy-directory):
Don't check existence of DIRNAME, this is done in
`tramp-skeleton-copy-directory' already.
* lisp/net/tramp-sh.el (tramp-sh-handle-copy-directory):
Apply `tramp-do-copy-or-rename-file-directly' if possible.
---
lisp/net/tramp-sh.el | 91 +++++++++++++++++++++++++++------------------------
lisp/net/tramp-smb.el | 3 --
2 files changed, 49 insertions(+), 45 deletions(-)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index e4e14912579..313a350fe0c 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -2020,48 +2020,55 @@ ID-FORMAT valid values are `string' and `integer'."
(t2 (tramp-tramp-file-p newname))
target)
(with-parsed-tramp-file-name (if t1 dirname newname) nil
- (unless (file-exists-p dirname)
- (tramp-error v 'file-missing dirname))
-
- (if (and copy-directory-create-symlink
- (setq target (file-symlink-p dirname))
- (tramp-equal-remote dirname newname))
- (make-symbolic-link
- target
- (if (directory-name-p newname)
- (concat newname (file-name-nondirectory dirname)) newname)
- t)
-
- (if (and (not copy-contents)
- (tramp-get-method-parameter v 'tramp-copy-recursive)
- ;; When DIRNAME and NEWNAME are remote, they must
- ;; have the same method.
- (or (null t1) (null t2)
- (string-equal
- (tramp-file-name-method
- (tramp-dissect-file-name dirname))
- (tramp-file-name-method
- (tramp-dissect-file-name newname)))))
- ;; scp or rsync DTRT.
- (progn
- (when (and (file-directory-p newname)
- (not (directory-name-p newname)))
- (tramp-error v 'file-already-exists newname))
- (setq dirname (directory-file-name (expand-file-name dirname))
- newname (directory-file-name (expand-file-name newname)))
- (when (and (file-directory-p newname)
- (not (string-equal (file-name-nondirectory dirname)
- (file-name-nondirectory
newname))))
- (setq newname
- (expand-file-name
- (file-name-nondirectory dirname) newname)))
- (unless (file-directory-p (file-name-directory newname))
- (make-directory (file-name-directory newname) parents))
- (tramp-do-copy-or-rename-file-out-of-band
- 'copy dirname newname 'ok-if-already-exists keep-date))
-
- ;; We must do it file-wise.
- (tramp-run-real-handler
+ (cond
+ ((and copy-directory-create-symlink
+ (setq target (file-symlink-p dirname))
+ (tramp-equal-remote dirname newname))
+ (make-symbolic-link
+ target
+ (if (directory-name-p newname)
+ (concat newname (file-name-nondirectory dirname)) newname)
+ t))
+
+ ;; Shortcut: if method, host, user are the same for both
+ ;; files, we invoke `cp' on the remote host directly.
+ ((and (not copy-contents)
+ (tramp-equal-remote dirname newname))
+ (when (and (file-directory-p newname)
+ (not (directory-name-p newname)))
+ (tramp-error v 'file-already-exists newname))
+ (setq dirname (directory-file-name (expand-file-name dirname))
+ newname (directory-file-name (expand-file-name newname)))
+ (tramp-do-copy-or-rename-file-directly
+ 'copy dirname newname
+ 'ok-if-already-exists keep-date 'preserve-uid-gid))
+
+ ;; scp or rsync DTRT.
+ ((and (not copy-contents)
+ (tramp-get-method-parameter v 'tramp-copy-recursive)
+ ;; When DIRNAME and NEWNAME are remote, they must have
+ ;; the same method.
+ (or (null t1) (null t2)
+ (string-equal
+ (tramp-file-name-method (tramp-dissect-file-name dirname))
+ (tramp-file-name-method (tramp-dissect-file-name
newname)))))
+ (when (and (file-directory-p newname)
+ (not (directory-name-p newname)))
+ (tramp-error v 'file-already-exists newname))
+ (setq dirname (directory-file-name (expand-file-name dirname))
+ newname (directory-file-name (expand-file-name newname)))
+ (when (and (file-directory-p newname)
+ (not (string-equal (file-name-nondirectory dirname)
+ (file-name-nondirectory newname))))
+ (setq newname
+ (expand-file-name (file-name-nondirectory dirname) newname)))
+ (unless (file-directory-p (file-name-directory newname))
+ (make-directory (file-name-directory newname) parents))
+ (tramp-do-copy-or-rename-file-out-of-band
+ 'copy dirname newname 'ok-if-already-exists keep-date))
+
+ ;; We must do it file-wise.
+ (t (tramp-run-real-handler
#'copy-directory
(list dirname newname keep-date parents copy-contents))))
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index da62773ccc6..2699dc13043 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -428,9 +428,6 @@ arguments to pass to the OPERATION."
(t2 (tramp-tramp-file-p newname))
target)
(with-parsed-tramp-file-name (if t1 dirname newname) nil
- (unless (file-exists-p dirname)
- (tramp-error v 'file-missing dirname))
-
(if (and copy-directory-create-symlink
(setq target (file-symlink-p dirname))
(tramp-equal-remote dirname newname))