mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-09-03 12:11:34 +00:00
create file volume's parent directory when necessary
Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
+20
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user