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.
This commit is contained in:
Michael Albinus 2017-05-03 21:49:32 +02:00
parent b867eb8ecf
commit a26e33a1a7
5 changed files with 16 additions and 13 deletions

View file

@ -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'

View file

@ -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.

View file

@ -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

View file

@ -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."

View file

@ -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)