emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r99387: Fix delete-directory recursio


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r99387: Fix delete-directory recursion behavior for trashing (Bug#5436).
Date: Tue, 26 Jan 2010 22:17:23 -0500
User-agent: Bazaar (2.0.2)

------------------------------------------------------------
revno: 99387
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Tue 2010-01-26 22:17:23 -0500
message:
  Fix delete-directory recursion behavior for trashing (Bug#5436).
  
  * files.el (delete-directory): Handle moving to trash without first doing 
recursion (Bug#5436).
modified:
  lisp/ChangeLog
  lisp/files.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-01-26 07:22:25 +0000
+++ b/lisp/ChangeLog    2010-01-27 03:17:23 +0000
@@ -1,3 +1,8 @@
+2010-01-27  David De La Harpe Golden  <address@hidden>
+
+       * files.el (delete-directory): Handle moving to trash without
+       first doing recursion (Bug#5436).
+
 2010-01-26  Dan Nicolaescu  <address@hidden>
 
        * vc-hooks.el (vc-path): Mark as obsolete.

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2010-01-17 02:25:53 +0000
+++ b/lisp/files.el     2010-01-27 03:17:23 +0000
@@ -4665,21 +4665,35 @@
   ;; delete-directory handler.
   (setq directory (directory-file-name (expand-file-name directory)))
   (let ((handler (find-file-name-handler directory 'delete-directory)))
-    (if handler
-       (funcall handler 'delete-directory directory recursive)
+    (cond
+     (handler
+      (funcall handler 'delete-directory directory recursive))
+     (delete-by-moving-to-trash
+      ;; Only move non-empty dir to trash if recursive deletion was
+      ;; requested.  This mimics the non-`delete-by-moving-to-trash'
+      ;; case, where the operation fails in delete-directory-internal.
+      ;; As `move-file-to-trash' trashes directories (empty or
+      ;; otherwise) as a unit, we do not need to recurse here.
+      (if (and (not recursive)
+              ;; Check if directory is empty apart from "." and "..".
+              (directory-files
+               directory 'full directory-files-no-dot-files-regexp))
+         (error "Directory is not empty, not moving to trash")
+       (move-file-to-trash directory)))
+     ;; Otherwise, call outselves recursively if needed.
+     (t
       (if (and recursive (not (file-symlink-p directory)))
-         (mapc
-          (lambda (file)
-            ;; This test is equivalent to
-            ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
-            ;; but more efficient
-            (if (eq t (car (file-attributes file)))
-                (delete-directory file recursive)
-              (delete-file file)))
-          ;; We do not want to delete "." and "..".
-          (directory-files
-           directory 'full directory-files-no-dot-files-regexp)))
-      (delete-directory-internal directory))))
+         (mapc (lambda (file)
+                 ;; This test is equivalent to
+                 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
+                 ;; but more efficient
+                 (if (eq t (car (file-attributes file)))
+                     (delete-directory file recursive)
+                   (delete-file file)))
+               ;; We do not want to delete "." and "..".
+               (directory-files
+                directory 'full directory-files-no-dot-files-regexp))
+       (delete-directory-internal directory))))))
 
 (defun copy-directory (directory newname &optional keep-time parents)
   "Copy DIRECTORY to NEWNAME.  Both args must be strings.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]