From d270d7d4ad8693202777ce29363947d38899bf6c Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 5 Nov 2019 12:58:47 +0100 Subject: [PATCH] Improve Tramp's copy-directory * lisp/net/tramp-adb.el (tramp-adb-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-sudoedit.el (tramp-sudoedit-file-name-handler-alist): Add `copy-directory'. * lisp/net/tramp.el (tramp-handle-copy-directory): New defun. --- lisp/net/tramp-adb.el | 2 +- lisp/net/tramp-gvfs.el | 2 +- lisp/net/tramp-rclone.el | 2 +- lisp/net/tramp-sudoedit.el | 2 +- lisp/net/tramp.el | 14 ++++++++++++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index e3098190e2b..a4f5760f72e 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -94,7 +94,7 @@ It is used for TCP/IP devices." '((access-file . tramp-handle-access-file) (add-name-to-file . tramp-handle-add-name-to-file) ;; `byte-compiler-base-file-name' performed by default handler. - ;; `copy-directory' performed by default handler. + (copy-directory . tramp-handle-copy-directory) (copy-file . tramp-adb-handle-copy-file) (delete-directory . tramp-adb-handle-delete-directory) (delete-file . tramp-adb-handle-delete-file) diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 6f5cade4c63..dbda24b9ac1 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -535,7 +535,7 @@ It has been changed in GVFS 1.14.") '((access-file . tramp-handle-access-file) (add-name-to-file . tramp-handle-add-name-to-file) ;; `byte-compiler-base-file-name' performed by default handler. - ;; `copy-directory' performed by default handler. + (copy-directory . tramp-handle-copy-directory) (copy-file . tramp-gvfs-handle-copy-file) (delete-directory . tramp-gvfs-handle-delete-directory) (delete-file . tramp-gvfs-handle-delete-file) diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index 2b3799ef008..56afdba7421 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el @@ -70,7 +70,7 @@ '((access-file . tramp-handle-access-file) (add-name-to-file . tramp-handle-add-name-to-file) ;; `byte-compiler-base-file-name' performed by default handler. - ;; `copy-directory' performed by default handler. + (copy-directory . tramp-handle-copy-directory) (copy-file . tramp-rclone-handle-copy-file) (delete-directory . tramp-rclone-handle-delete-directory) (delete-file . tramp-rclone-handle-delete-file) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index 2d9d7ff7892..e7a892c7465 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -66,7 +66,7 @@ See `tramp-actions-before-shell' for more info.") '((access-file . tramp-handle-access-file) (add-name-to-file . tramp-sudoedit-handle-add-name-to-file) (byte-compiler-base-file-name . ignore) - ;; `copy-directory' performed by default handler. + (copy-directory . tramp-handle-copy-directory) (copy-file . tramp-sudoedit-handle-copy-file) (delete-directory . tramp-sudoedit-handle-delete-directory) (delete-file . tramp-sudoedit-handle-delete-file) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 88ff36d98ea..acb5a93687c 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3016,6 +3016,20 @@ User is always nil." filename newname 'ok-if-already-exists 'keep-time 'preserve-uid-gid 'preserve-permissions))) +(defun tramp-handle-copy-directory + (directory newname &optional keep-date parents copy-contents) + "Like `copy-directory' for Tramp files." + ;; `directory-files' creates `newname' before running this check. + ;; So we do it ourselves. + (unless (file-exists-p directory) + (tramp-error + (tramp-dissect-file-name directory) tramp-file-missing + "No such file or directory" directory)) + ;; We must do it file-wise. + (tramp-run-real-handler + 'copy-directory + (list directory newname keep-date parents copy-contents))) + (defun tramp-handle-directory-file-name (directory) "Like `directory-file-name' for Tramp files." ;; If localname component of filename is "/", leave it unchanged. -- 2.39.5