Auto create parent directories for rename support
Sometimes renames will move a file into a directory that does not yet exist. This will create the parent directories, using the same symlink logic, to ensure that there is a valid destination. Bug: 16458395 Change-Id: Iaa005a12ce800c39f4db20f7c25a2a68cb40a52d
This commit is contained in:
+5
-3
@@ -357,8 +357,10 @@ Value* RenameFn(const char* name, State* state, int argc, Expr* argv[]) {
|
|||||||
name);
|
name);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (make_parents(dst_name) != 0) {
|
||||||
if (rename(src_name, dst_name) != 0) {
|
ErrorAbort(state, "Creating parent of %s() failed, error %s()",
|
||||||
|
dst_name, strerror(errno));
|
||||||
|
} else if (rename(src_name, dst_name) != 0) {
|
||||||
ErrorAbort(state, "Rename of %s() to %s() failed, error %s()",
|
ErrorAbort(state, "Rename of %s() to %s() failed, error %s()",
|
||||||
src_name, dst_name, strerror(errno));
|
src_name, dst_name, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
@@ -642,7 +644,7 @@ static int make_parents(char* name) {
|
|||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (make_parents(name) < 0) return -1;
|
if (make_parents(name) < 0) return -1;
|
||||||
int result = mkdir(name, 0700);
|
int result = mkdir(name, 0700);
|
||||||
if (result == 0) printf("symlink(): created [%s]\n", name);
|
if (result == 0) printf("created [%s]\n", name);
|
||||||
*p = '/';
|
*p = '/';
|
||||||
if (result == 0 || errno == EEXIST) {
|
if (result == 0 || errno == EEXIST) {
|
||||||
// successfully created or already existed; we're done
|
// successfully created or already existed; we're done
|
||||||
|
|||||||
@@ -19,4 +19,6 @@
|
|||||||
|
|
||||||
void RegisterInstallFunctions();
|
void RegisterInstallFunctions();
|
||||||
|
|
||||||
|
static int make_parents(char* name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user