Commit 3763ee85 by Stéphane Graber

Revert "utils: reimplement/fix mkdir_p()"

This reverts commit 8de41406. This commit was preventing container startup on my machine, making them all fail with various "No such file or directory" errors. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 8de41406
......@@ -95,25 +95,39 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
return 0;
}
static int is_all_slashes(char *path)
{
while (*path && *path == '/')
path++;
if (*path)
return 0;
return 1;
}
extern int mkdir_p(char *dir, mode_t mode)
{
char *tmp = dir;
char *orig = dir;
char *makeme;
do {
dir = tmp + strspn(tmp, "/");
tmp = dir + strcspn(dir, "/");
makeme = strndupa(orig, dir - orig);
if (*makeme) {
if (!access(makeme, F_OK))
return 0;
if (mkdir(makeme, mode)) {
SYSERROR("failed to create directory '%s'\n", makeme);
return -1;
}
}
} while(tmp != dir);
int ret;
char *d;
if (is_all_slashes(dir))
return 0;
d = strdup(dir);
if (!d)
return -1;
ret = mkdir_p(dirname(d), mode);
free(d);
if (ret)
return -1;
if (!access(dir, F_OK))
return 0;
if (mkdir(dir, mode)) {
SYSERROR("failed to create directory '%s'\n", dir);
return -1;
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment