diff --git a/src/util.c b/src/util.c index c1be6b9..2308c68 100644 --- a/src/util.c +++ b/src/util.c @@ -208,6 +208,23 @@ int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroup return ret; } +static int hyper_create_parent_dir(const char *hyper_path) +{ + char *p, *path = strdup(hyper_path); + int ret = 0; + + if (path == NULL) + return -1; + p = strrchr(path, '/'); + if (p != NULL && p != path) { + *p = '\0'; + ret = hyper_mkdir(path, 0777); + } + free(path); + + return ret; +} + int hyper_create_file(const char *hyper_path) { int fd; @@ -220,6 +237,9 @@ int hyper_create_file(const char *hyper_path) return -1; } + if (hyper_create_parent_dir(hyper_path) < 0) + return -1; + fd = open(hyper_path, O_CREAT|O_WRONLY, 0666); if (fd < 0) return -1;