comparison src/fileio.c @ 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 4040ecb0c904
children 6e7738cc419f
comparison
equal deleted inserted replaced
106993:ba0145049d09 106994:8b0707b50290
212 212
213 Lisp_Object Qdelete_by_moving_to_trash; 213 Lisp_Object Qdelete_by_moving_to_trash;
214 214
215 /* Lisp function for moving files to trash. */ 215 /* Lisp function for moving files to trash. */
216 Lisp_Object Qmove_file_to_trash; 216 Lisp_Object Qmove_file_to_trash;
217
218 /* Lisp function for recursively copying directories. */
219 Lisp_Object Qcopy_directory;
220
221 /* Lisp function for recursively deleting directories. */
222 Lisp_Object Qdelete_directory;
217 223
218 extern Lisp_Object Vuser_login_name; 224 extern Lisp_Object Vuser_login_name;
219 225
220 #ifdef WINDOWSNT 226 #ifdef WINDOWSNT
221 extern Lisp_Object Vw32_get_true_file_attributes; 227 extern Lisp_Object Vw32_get_true_file_attributes;
2239 /* If the file names are identical but for the case, 2245 /* If the file names are identical but for the case,
2240 don't attempt to move directory to itself. */ 2246 don't attempt to move directory to itself. */
2241 && (NILP (Fstring_equal (Fdowncase (file), Fdowncase (newname)))) 2247 && (NILP (Fstring_equal (Fdowncase (file), Fdowncase (newname))))
2242 #endif 2248 #endif
2243 ) 2249 )
2244 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); 2250 {
2251 Lisp_Object fname = NILP (Ffile_directory_p (file))
2252 ? file : Fdirectory_file_name (file);
2253 newname = Fexpand_file_name (Ffile_name_nondirectory (fname), newname);
2254 }
2245 else 2255 else
2246 newname = Fexpand_file_name (newname, Qnil); 2256 newname = Fexpand_file_name (newname, Qnil);
2247 2257
2248 /* If the file name has special constructs in it, 2258 /* If the file name has special constructs in it,
2249 call the corresponding file handler. */ 2259 call the corresponding file handler. */
2277 if (! NILP (symlink_target)) 2287 if (! NILP (symlink_target))
2278 Fmake_symbolic_link (symlink_target, newname, 2288 Fmake_symbolic_link (symlink_target, newname,
2279 NILP (ok_if_already_exists) ? Qnil : Qt); 2289 NILP (ok_if_already_exists) ? Qnil : Qt);
2280 else 2290 else
2281 #endif 2291 #endif
2292 if (Ffile_directory_p (file))
2293 call4 (Qcopy_directory, file, newname, Qt, Qnil);
2294 else
2295 /* We have already prompted if it was an integer, so don't
2296 have copy-file prompt again. */
2282 Fcopy_file (file, newname, 2297 Fcopy_file (file, newname,
2283 /* We have already prompted if it was an integer,
2284 so don't have copy-file prompt again. */
2285 NILP (ok_if_already_exists) ? Qnil : Qt, 2298 NILP (ok_if_already_exists) ? Qnil : Qt,
2286 Qt, Qt); 2299 Qt, Qt);
2287 2300
2288 count = SPECPDL_INDEX (); 2301 count = SPECPDL_INDEX ();
2289 specbind (Qdelete_by_moving_to_trash, Qnil); 2302 specbind (Qdelete_by_moving_to_trash, Qnil);
2290 Fdelete_file (file); 2303 if (Ffile_directory_p (file))
2304 call2 (Qdelete_directory, file, Qt);
2305 else
2306 Fdelete_file (file);
2291 unbind_to (count, Qnil); 2307 unbind_to (count, Qnil);
2292 } 2308 }
2293 else 2309 else
2294 report_file_error ("Renaming", list2 (file, newname)); 2310 report_file_error ("Renaming", list2 (file, newname));
2295 } 2311 }
5725 `delete-file' and `delete-directory'. */); 5741 `delete-file' and `delete-directory'. */);
5726 delete_by_moving_to_trash = 0; 5742 delete_by_moving_to_trash = 0;
5727 Qdelete_by_moving_to_trash = intern_c_string ("delete-by-moving-to-trash"); 5743 Qdelete_by_moving_to_trash = intern_c_string ("delete-by-moving-to-trash");
5728 Qmove_file_to_trash = intern_c_string ("move-file-to-trash"); 5744 Qmove_file_to_trash = intern_c_string ("move-file-to-trash");
5729 staticpro (&Qmove_file_to_trash); 5745 staticpro (&Qmove_file_to_trash);
5746 Qcopy_directory = intern_c_string ("copy-directory");
5747 staticpro (&Qcopy_directory);
5748 Qdelete_directory = intern_c_string ("delete-directory");
5749 staticpro (&Qdelete_directory);
5730 5750
5731 defsubr (&Sfind_file_name_handler); 5751 defsubr (&Sfind_file_name_handler);
5732 defsubr (&Sfile_name_directory); 5752 defsubr (&Sfile_name_directory);
5733 defsubr (&Sfile_name_nondirectory); 5753 defsubr (&Sfile_name_nondirectory);
5734 defsubr (&Sunhandled_file_name_directory); 5754 defsubr (&Sunhandled_file_name_directory);