diff options
| author | Chong Yidong | 2010-01-26 22:17:23 -0500 |
|---|---|---|
| committer | Chong Yidong | 2010-01-26 22:17:23 -0500 |
| commit | 8b0e68ea3fd559cbdfd0c532d789d0bad73890df (patch) | |
| tree | 790933f833dc45654a0b192ad1f730dbe2703db9 | |
| parent | 368d3208cfceb42b5ee07c61b4aa5b7d09c9f2bf (diff) | |
| download | emacs-8b0e68ea3fd559cbdfd0c532d789d0bad73890df.tar.gz emacs-8b0e68ea3fd559cbdfd0c532d789d0bad73890df.zip | |
Fix delete-directory recursion behavior for trashing (Bug#5436).
* files.el (delete-directory): Handle moving to trash without first doing recursion (Bug#5436).
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/files.el | 42 |
2 files changed, 33 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5097af5c1ed..5aa791342f2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2010-01-27 David De La Harpe Golden <david@harpegolden.net> | ||
| 2 | |||
| 3 | * files.el (delete-directory): Handle moving to trash without | ||
| 4 | first doing recursion (Bug#5436). | ||
| 5 | |||
| 1 | 2010-01-26 Dan Nicolaescu <dann@ics.uci.edu> | 6 | 2010-01-26 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 7 | ||
| 3 | * vc-hooks.el (vc-path): Mark as obsolete. | 8 | * vc-hooks.el (vc-path): Mark as obsolete. |
diff --git a/lisp/files.el b/lisp/files.el index 99e818643d0..bcaba300ae6 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -4665,21 +4665,35 @@ If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well." | |||
| 4665 | ;; delete-directory handler. | 4665 | ;; delete-directory handler. |
| 4666 | (setq directory (directory-file-name (expand-file-name directory))) | 4666 | (setq directory (directory-file-name (expand-file-name directory))) |
| 4667 | (let ((handler (find-file-name-handler directory 'delete-directory))) | 4667 | (let ((handler (find-file-name-handler directory 'delete-directory))) |
| 4668 | (if handler | 4668 | (cond |
| 4669 | (funcall handler 'delete-directory directory recursive) | 4669 | (handler |
| 4670 | (funcall handler 'delete-directory directory recursive)) | ||
| 4671 | (delete-by-moving-to-trash | ||
| 4672 | ;; Only move non-empty dir to trash if recursive deletion was | ||
| 4673 | ;; requested. This mimics the non-`delete-by-moving-to-trash' | ||
| 4674 | ;; case, where the operation fails in delete-directory-internal. | ||
| 4675 | ;; As `move-file-to-trash' trashes directories (empty or | ||
| 4676 | ;; otherwise) as a unit, we do not need to recurse here. | ||
| 4677 | (if (and (not recursive) | ||
| 4678 | ;; Check if directory is empty apart from "." and "..". | ||
| 4679 | (directory-files | ||
| 4680 | directory 'full directory-files-no-dot-files-regexp)) | ||
| 4681 | (error "Directory is not empty, not moving to trash") | ||
| 4682 | (move-file-to-trash directory))) | ||
| 4683 | ;; Otherwise, call outselves recursively if needed. | ||
| 4684 | (t | ||
| 4670 | (if (and recursive (not (file-symlink-p directory))) | 4685 | (if (and recursive (not (file-symlink-p directory))) |
| 4671 | (mapc | 4686 | (mapc (lambda (file) |
| 4672 | (lambda (file) | 4687 | ;; This test is equivalent to |
| 4673 | ;; This test is equivalent to | 4688 | ;; (and (file-directory-p fn) (not (file-symlink-p fn))) |
| 4674 | ;; (and (file-directory-p fn) (not (file-symlink-p fn))) | 4689 | ;; but more efficient |
| 4675 | ;; but more efficient | 4690 | (if (eq t (car (file-attributes file))) |
| 4676 | (if (eq t (car (file-attributes file))) | 4691 | (delete-directory file recursive) |
| 4677 | (delete-directory file recursive) | 4692 | (delete-file file))) |
| 4678 | (delete-file file))) | 4693 | ;; We do not want to delete "." and "..". |
| 4679 | ;; We do not want to delete "." and "..". | 4694 | (directory-files |
| 4680 | (directory-files | 4695 | directory 'full directory-files-no-dot-files-regexp)) |
| 4681 | directory 'full directory-files-no-dot-files-regexp))) | 4696 | (delete-directory-internal directory)))))) |
| 4682 | (delete-directory-internal directory)))) | ||
| 4683 | 4697 | ||
| 4684 | (defun copy-directory (directory newname &optional keep-time parents) | 4698 | (defun copy-directory (directory newname &optional keep-time parents) |
| 4685 | "Copy DIRECTORY to NEWNAME. Both args must be strings. | 4699 | "Copy DIRECTORY to NEWNAME. Both args must be strings. |