changeset 106994:8b0707b50290

Fix rename-file to handle directory renaming properly (Bug#3353). * fileio.c (Frename_file): Call copy-directory and delete-directory for directories, in order to handle cross-device renaming.
author Chong Yidong <cyd@stupidchicken.com>
date Tue, 26 Jan 2010 23:08:41 -0500
parents ba0145049d09
children 001a0729d255
files src/ChangeLog src/fileio.c
diffstat 2 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Jan 26 20:00:54 2010 -0800
+++ b/src/ChangeLog	Tue Jan 26 23:08:41 2010 -0500
@@ -1,3 +1,9 @@
+2010-01-27  David De La Harpe Golden  <david@harpegolden.net>
+
+	* fileio.c (Frename_file): Call copy-directory and
+	delete-directory for directories, in order to handle cross-device
+	renaming (Bug#3353).
+
 2010-01-25  Jan Djärv  <jan.h.d@swipnet.se>
 
 	* xfns.c (Fx_create_frame): If frame height is too big, try
@@ -9323,7 +9329,7 @@
 	(syms_of_xterm): Don't declare it any more.
 	(x_draw_glyph_string): Adjust to the new name.
 
-2008-06-10  David De La Harpe Golden  <david@harpegolden.net>  (tiny change)
+2008-06-10  David De La Harpe Golden  <david@harpegolden.net>
 
 	* xterm.c (x_underline_minimum_display_offset): New var.
 	(x_draw_glyph_string): Use it.
--- a/src/fileio.c	Tue Jan 26 20:00:54 2010 -0800
+++ b/src/fileio.c	Tue Jan 26 23:08:41 2010 -0500
@@ -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);
+    {
+      Lisp_Object fname = NILP (Ffile_directory_p (file))
+	? file : Fdirectory_file_name (file);
+      newname = Fexpand_file_name (Ffile_name_nondirectory (fname), newname);
+    }
   else
     newname = Fexpand_file_name (newname, Qnil);
 
@@ -2279,15 +2289,21 @@
                                  NILP (ok_if_already_exists) ? Qnil : Qt);
           else
 #endif
+	  if (Ffile_directory_p (file))
+	    call4 (Qcopy_directory, file, newname, Qt, Qnil);
+	  else
+	    /* We have already prompted if it was an integer, so don't
+	       have copy-file prompt again.  */
 	    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 +5743,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);