(rename_directory): New function

This commit is contained in:
Sergey Poznyakoff
2006-05-08 12:09:46 +00:00
parent 192ac7136a
commit a0b4431f26

View 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)
{