bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#5436: 23.1.91; Deleting directories causes unusable file layout in f


From: David De La Harpe Golden
Subject: bug#5436: 23.1.91; Deleting directories causes unusable file layout in freedesktop trashcan
Date: Sun, 24 Jan 2010 20:25:32 +0000
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109)

#$%? missed a "not" in one of the comments. Only noticed just after send. Further slight comments improvement attached. Sorry.




# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: address@hidden
# target_branch: http://bzr.savannah.gnu.org/r/emacs/trunk/
# testament_sha1: 148945194f5afb56b9c652a4a14e1a222aabe40b
# timestamp: 2010-01-24 20:25:06 +0000
# base_revision_id: address@hidden
# 
# Begin patch
=== modified file 'lisp/files.el'
--- lisp/files.el       2010-01-17 02:25:53 +0000
+++ lisp/files.el       2010-01-24 20:24:59 +0000
@@ -4667,19 +4667,37 @@
   (let ((handler (find-file-name-handler directory 'delete-directory)))
     (if handler
        (funcall handler 'delete-directory directory recursive)
-      (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))))
+      (if delete-by-moving-to-trash
+          ;; To mimic the non- delete-by-moving-to-trash case, which
+          ;; will (sensibly) fail (in delete-directory-internal) if
+          ;; the directory is not empty and recursion wasn't
+          ;; requested, only move non-empty directories to trash if
+          ;; recursive deletion was requested.  As move-file-to-trash
+          ;; moves directories, empty or otherwise, into the trash as
+          ;; a unit, we do not need to recurse ourselves here.
+          (if (and (not recursive)
+                   ;; Check if directory is not empty apart from "." and "..".
+                   (directory-files
+                    directory 'full directory-files-no-dot-files-regexp))
+              (error "Directory is not empty, not moving to trash.")
+            ;; Either recursive, or not recursive but directory is
+            ;; empty, so we can move directory to trash.
+            (move-file-to-trash directory))
+        ;; Recurse ourselves since we're not moving to trash.
+        (progn
+          (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))))))
 
 (defun copy-directory (directory newname &optional keep-time parents)
   "Copy DIRECTORY to NEWNAME.  Both args must be strings.
@@ -6170,7 +6188,8 @@
   "Move the file (or directory) named FILENAME to the trash.
 When `delete-by-moving-to-trash' is non-nil, this function is
 called by `delete-file' and `delete-directory' instead of
-deleting files outright.
+deleting files outright.  If FILENAME is a directory, it may
+be empty or non-empty.
 
 If the function `system-move-file-to-trash' is defined, call it
  with FILENAME as an argument.

=== modified file 'src/fileio.c'
--- src/fileio.c        2010-01-13 04:33:42 +0000
+++ src/fileio.c        2010-01-24 20:11:15 +0000
@@ -215,6 +215,12 @@
 /* Lisp function for moving files to trash.  */
 Lisp_Object Qmove_file_to_trash;
 
+/* Lisp function for recursively copying directories.  */
+Lisp_Object Qcopy_directory;
+
+/* Lisp function for recursively deleting directories.  */
+Lisp_Object Qdelete_directory;
+
 extern Lisp_Object Vuser_login_name;
 
 #ifdef WINDOWSNT
@@ -2241,7 +2247,11 @@
       && (NILP (Fstring_equal (Fdowncase (file), Fdowncase (newname))))
 #endif
       )
-    newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
+
+    if (!NILP (Ffile_directory_p (file)))
+      newname = Fexpand_file_name (Ffile_name_nondirectory 
(Fdirectory_file_name (file)), newname);
+    else
+      newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
   else
     newname = Fexpand_file_name (newname, Qnil);
 
@@ -2279,15 +2289,23 @@
                                  NILP (ok_if_already_exists) ? Qnil : Qt);
           else
 #endif
-           Fcopy_file (file, newname,
-                       /* We have already prompted if it was an integer,
-                          so don't have copy-file prompt again.  */
-                       NILP (ok_if_already_exists) ? Qnil : Qt,
-                       Qt, Qt);
+            {
+              if ( Ffile_directory_p (file) )
+                call4 (Qcopy_directory, file, newname, Qt, Qnil);
+              else
+                Fcopy_file (file, newname,
+                            /* We have already prompted if it was an integer,
+                               so don't have copy-file prompt again.  */
+                            NILP (ok_if_already_exists) ? Qnil : Qt,
+                            Qt, Qt);
+            }
 
          count = SPECPDL_INDEX ();
          specbind (Qdelete_by_moving_to_trash, Qnil);
-         Fdelete_file (file);
+          if ( Ffile_directory_p (file) )
+            call2 (Qdelete_directory, file, Qt);
+          else
+            Fdelete_file (file);
          unbind_to (count, Qnil);
        }
       else
@@ -5727,6 +5745,10 @@
   Qdelete_by_moving_to_trash = intern_c_string ("delete-by-moving-to-trash");
   Qmove_file_to_trash = intern_c_string ("move-file-to-trash");
   staticpro (&Qmove_file_to_trash);
+  Qcopy_directory = intern_c_string ("copy-directory");
+  staticpro (&Qcopy_directory);
+  Qdelete_directory = intern_c_string ("delete-directory");
+  staticpro (&Qdelete_directory);
 
   defsubr (&Sfind_file_name_handler);
   defsubr (&Sfile_name_directory);

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWbRXlCwACo7/gFVf6Eh59///
/+f+gL////pgD+X193OoN8cK4oUAAAJlN3Kpu93vWKLb0DoGgAuyugJJIKeQYk2gyp6maZpqZJsk
ekyZABoA0BiaBoJJACYgQIhGoG1NAA9QDQAAAAD0hwNBpkNNGhhAyGhgjQ0yaNAMgxAAGgkKQmpG
00j0amaI0AZBiNqfqj0mahoAADQACSpqm1NND0gxNG9UNDIwEBhNGTJkGIGQaYIwiiIAiYCNTTCG
mUzQRp6gymgAyAA0NNNExgYBGfdarLlqqO4BLUdkYw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