From: Michael Albinus Date: Wed, 3 May 2017 19:49:32 +0000 (+0200) Subject: Fix Bug#26763 X-Git-Tag: emacs-26.0.90~521^2~480 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a26e33a1a776affcbf8cdd012297d48999ba8e80;p=emacs.git Fix Bug#26763 * lisp/files.el (delete-directory): Call file name handler with `trash' argument. * lisp/net/ange-ftp.el (ange-ftp-delete-directory): * lisp/net/tramp-sh.el (tramp-sh-handle-delete-directory): Add TRASH arg. Implement it. (Bug#26763) (tramp-get-remote-trash): Check for `delete-by-moving-to-trash'. * lisp/net/tramp-adb.el (tramp-adb-handle-delete-directory): * lisp/net/tramp-smb.el (tramp-smb-handle-delete-directory): Add _TRASH arg. --- diff --git a/lisp/files.el b/lisp/files.el index 0978fa254f6..d193749bb88 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5477,7 +5477,7 @@ RECURSIVE if DIRECTORY is nonempty." (let ((handler (find-file-name-handler directory 'delete-directory))) (cond (handler - (funcall handler 'delete-directory directory recursive)) + (funcall handler 'delete-directory directory recursive trash)) ((and delete-by-moving-to-trash trash) ;; Only move non-empty dir to trash if recursive deletion was ;; requested. This mimics the non-`delete-by-moving-to-trash' diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el index cd0ae8d4203..7b8b3fc8809 100644 --- a/lisp/net/ange-ftp.el +++ b/lisp/net/ange-ftp.el @@ -4128,15 +4128,15 @@ directory, so that Emacs will know its current contents." (ange-ftp-add-file-entry dir t)) (ange-ftp-real-make-directory dir))))) -(defun ange-ftp-delete-directory (dir &optional recursive) +(defun ange-ftp-delete-directory (dir &optional recursive trash) (if (file-directory-p dir) (let ((parsed (ange-ftp-ftp-name dir))) (if recursive (mapc (lambda (file) (if (file-directory-p file) - (ange-ftp-delete-directory file recursive) - (delete-file file))) + (ange-ftp-delete-directory file recursive trash) + (delete-file file trash))) ;; We do not want to delete "." and "..". (directory-files dir 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))) @@ -4170,7 +4170,7 @@ directory, so that Emacs will know its current contents." dir (cdr result)))) (ange-ftp-delete-file-entry dir t)) - (ange-ftp-real-delete-directory dir recursive))) + (ange-ftp-real-delete-directory dir recursive trash))) (error "Not a directory: %s" dir))) ;; Make a local copy of FILE and return its name. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 240e017279c..a80bc0bdb2a 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -521,7 +521,7 @@ Emacs dired can't find files." (tramp-flush-file-property v (file-name-directory localname)) (tramp-flush-directory-property v localname))) -(defun tramp-adb-handle-delete-directory (directory &optional recursive) +(defun tramp-adb-handle-delete-directory (directory &optional recursive _trash) "Like `delete-directory' for Tramp files." (setq directory (expand-file-name directory)) (with-parsed-tramp-file-name (file-truename directory) nil diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 475f2b9a5d1..71afb9aeb75 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2566,7 +2566,7 @@ The method used must be an out-of-band method." (tramp-shell-quote-argument localname)) "Couldn't make directory %s" dir)))) -(defun tramp-sh-handle-delete-directory (directory &optional recursive) +(defun tramp-sh-handle-delete-directory (directory &optional recursive trash) "Like `delete-directory' for Tramp files." (setq directory (expand-file-name directory)) (with-parsed-tramp-file-name directory nil @@ -2574,7 +2574,8 @@ The method used must be an out-of-band method." (tramp-flush-directory-property v localname) (tramp-barf-unless-okay v (format "cd / && %s %s" - (if recursive "rm -rf" "rmdir") + (or (and trash (tramp-get-remote-trash v)) + (if recursive "rm -rf" "rmdir")) (tramp-shell-quote-argument localname)) "Couldn't delete %s" directory))) @@ -5394,10 +5395,12 @@ Nonexistent directories are removed from spec." result)))) (defun tramp-get-remote-trash (vec) - "Determine remote `trash' command." - (with-tramp-connection-property vec "trash" - (tramp-message vec 5 "Finding a suitable `trash' command") - (tramp-find-executable vec "trash" (tramp-get-remote-path vec)))) + "Determine remote `trash' command. +This command is returned only if `delete-by-moving-to-trash' is non-nil." + (and delete-by-moving-to-trash + (with-tramp-connection-property vec "trash" + (tramp-message vec 5 "Finding a suitable `trash' command") + (tramp-find-executable vec "trash" (tramp-get-remote-path vec))))) (defun tramp-get-remote-touch (vec) "Determine remote `touch' command." diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 4205376d655..014e1e86011 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -617,7 +617,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (tramp-compat-file-attribute-modification-time (file-attributes filename)))))) -(defun tramp-smb-handle-delete-directory (directory &optional recursive) +(defun tramp-smb-handle-delete-directory (directory &optional recursive _trash) "Like `delete-directory' for Tramp files." (setq directory (directory-file-name (expand-file-name directory))) (when (file-exists-p directory)