From: Sergey Poznyakoff Date: Mon, 8 May 2006 12:09:46 +0000 (+0000) Subject: (rename_directory): New function X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=a0b4431f26a72addb201c306ae02c2e12c2d5092;p=chaz%2Ftar (rename_directory): New function --- diff --git a/src/extract.c b/src/extract.c index 4082083..d346f79 100644 --- a/src/extract.c +++ b/src/extract.c @@ -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) {