]> Dogcows Code - chaz/tar/commitdiff
(rename_directory): New function
authorSergey Poznyakoff <gray@gnu.org.ua>
Mon, 8 May 2006 12:09:46 +0000 (12:09 +0000)
committerSergey Poznyakoff <gray@gnu.org.ua>
Mon, 8 May 2006 12:09:46 +0000 (12:09 +0000)
src/extract.c

index 408208392ab64a69afd7a116c4c12960117ba5f2..d346f79ac272a04344ed7e78ccafe55aa28a14fa 100644 (file)
@@ -392,13 +392,12 @@ static int
 make_directories (char *file_name)
 {
   char *cursor0 = file_name + FILE_SYSTEM_PREFIX_LEN (file_name);
-  char *cursor;                        /* points into the file name */
+  char *cursor;                        /* points into the file name */
   int did_something = 0;       /* did we do anything yet? */
   int mode;
   int invert_permissions;
   int status;
 
-
   for (cursor = cursor0; *cursor; cursor++)
     {
       if (! ISSLASH (*cursor))
@@ -1323,6 +1322,39 @@ extract_finish (void)
   apply_nonancestor_delayed_set_stat ("", 1);
 }
 
+bool
+rename_directory (char *src, char *dst)
+{
+  if (rename (src, dst))
+    {
+      int e = errno;
+
+      switch (e)
+       {
+       case ENOENT:
+         if (make_directories (dst))
+           {
+             if (rename (src, dst) == 0)
+               return true;
+             e = errno;
+           }
+         break;
+                   
+       case EXDEV:
+         /* FIXME: Fall back to recursive copying */
+         
+       default:
+         break;
+       }
+
+      ERROR ((0, e, _("Cannot rename %s to %s"),
+             quote_n (0, src),
+             quote_n (1, dst)));
+      return false;
+    }
+  return true;
+}
+      
 void
 fatal_exit (void)
 {
This page took 0.028891 seconds and 4 git commands to generate.