mirror of https://github.com/schoebel/mars
generic: avoid auto-creation of toplevel dir
This commit is contained in:
parent
b0cf462ae6
commit
04b1f38057
|
@ -1096,7 +1096,7 @@ int ordered_symlink(const char *oldpath,
|
||||||
status = mars_symlink(oldpath, newpath, stamp, true);
|
status = mars_symlink(oldpath, newpath, stamp, true);
|
||||||
|
|
||||||
/* Automatically create any missing path dirs */
|
/* Automatically create any missing path dirs */
|
||||||
while (unlikely(status < 0)) {
|
while (unlikely(status < 0 && status != -EEXIST)) {
|
||||||
int old_len;
|
int old_len;
|
||||||
int check;
|
int check;
|
||||||
|
|
||||||
|
@ -1104,12 +1104,20 @@ int ordered_symlink(const char *oldpath,
|
||||||
dir_path = brick_strdup(newpath);
|
dir_path = brick_strdup(newpath);
|
||||||
dir_len = strlen(dir_path);
|
dir_len = strlen(dir_path);
|
||||||
}
|
}
|
||||||
|
/* skip backwards to the slash */
|
||||||
old_len = dir_len;
|
old_len = dir_len;
|
||||||
while (dir_len > 0 && dir_path[dir_len] != '/')
|
while (dir_len > 0 && dir_path[dir_len] != '/')
|
||||||
dir_len--;
|
dir_len--;
|
||||||
dir_path[dir_len] = '\0';
|
dir_path[dir_len] = '\0';
|
||||||
if (dir_len <= 0 || dir_len >= old_len)
|
if (dir_len <= 0 || dir_len >= old_len)
|
||||||
break;
|
break;
|
||||||
|
/* ensure that top-level dir is not created. */
|
||||||
|
dir_len--;
|
||||||
|
while (dir_len > 0 && dir_path[dir_len] != '/')
|
||||||
|
dir_len--;
|
||||||
|
if (dir_len <= 0 || dir_len >= old_len)
|
||||||
|
break;
|
||||||
|
/* create the interim dir */
|
||||||
check = mars_mkdir(dir_path);
|
check = mars_mkdir(dir_path);
|
||||||
if (check >= 0) {
|
if (check >= 0) {
|
||||||
brick_string_free(dir_path);
|
brick_string_free(dir_path);
|
||||||
|
@ -1117,6 +1125,8 @@ int ordered_symlink(const char *oldpath,
|
||||||
if (nr_retry++ < 3)
|
if (nr_retry++ < 3)
|
||||||
goto retry;
|
goto retry;
|
||||||
break;
|
break;
|
||||||
|
} else if (check == -EEXIST) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
brick_string_free(dir_path);
|
brick_string_free(dir_path);
|
||||||
|
|
Loading…
Reference in New Issue