diff lisp/files.el @ 107627:1465e84ffdb0

Merge from mainline.
author Eli Zaretskii <eliz@gnu.org>
date Fri, 29 Jan 2010 06:13:16 -0500
parents 405563a1dc5c
children 541b767fb366
line wrap: on
line diff
--- a/lisp/files.el	Mon Jan 25 12:42:44 2010 -0500
+++ b/lisp/files.el	Fri Jan 29 06:13:16 2010 -0500
@@ -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.