Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit da986b4

Browse files
committed
create file volume's parent directory when necessary
Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent 2f4626d commit da986b4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/util.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroup
208208
return ret;
209209
}
210210

211+
static int hyper_create_parent_dir(const char *hyper_path)
212+
{
213+
char *p, *path = strdup(hyper_path);
214+
int ret = 0;
215+
216+
if (path == NULL)
217+
return -1;
218+
p = strrchr(path, '/');
219+
if (p != NULL && p != path) {
220+
*p = '\0';
221+
ret = hyper_mkdir(path, 0777);
222+
}
223+
free(path);
224+
225+
return ret;
226+
}
227+
211228
int hyper_create_file(const char *hyper_path)
212229
{
213230
int fd;
@@ -220,6 +237,9 @@ int hyper_create_file(const char *hyper_path)
220237
return -1;
221238
}
222239

240+
if (hyper_create_parent_dir(hyper_path) < 0)
241+
return -1;
242+
223243
fd = open(hyper_path, O_CREAT|O_WRONLY, 0666);
224244
if (fd < 0)
225245
return -1;

0 commit comments

Comments
 (0)