generic: avoid auto-creation of toplevel dir

This commit is contained in:
Thomas Schoebel-Theuer 2022-09-06 11:04:08 +02:00
parent b0cf462ae6
commit 04b1f38057
1 changed files with 11 additions and 1 deletions

View File

@ -1096,7 +1096,7 @@ int ordered_symlink(const char *oldpath,
status = mars_symlink(oldpath, newpath, stamp, true);
/* Automatically create any missing path dirs */
while (unlikely(status < 0)) {
while (unlikely(status < 0 && status != -EEXIST)) {
int old_len;
int check;
@ -1104,12 +1104,20 @@ int ordered_symlink(const char *oldpath,
dir_path = brick_strdup(newpath);
dir_len = strlen(dir_path);
}
/* skip backwards to the slash */
old_len = dir_len;
while (dir_len > 0 && dir_path[dir_len] != '/')
dir_len--;
dir_path[dir_len] = '\0';
if (dir_len <= 0 || dir_len >= old_len)
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);
if (check >= 0) {
brick_string_free(dir_path);
@ -1117,6 +1125,8 @@ int ordered_symlink(const char *oldpath,
if (nr_retry++ < 3)
goto retry;
break;
} else if (check == -EEXIST) {
break;
}
}
brick_string_free(dir_path);