mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-09-07 14:11:36 +00:00
handle directory destination for a file volume binding
If the destination directoroy does not exist in the base image, create it as a file instead, following docker's practice. [hyperpublic@hyperhq]$docker run -t -i -v /home/bergwolf/bin/procmuttmail:/vol/data/ busybox / # ls -l /vol/data -rwxr-xr-x 1 1000 1000 28 Apr 17 05:38 /vol/data / # Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
@@ -144,6 +144,7 @@ static int container_setup_volume(struct hyper_container *container)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hyper_filize(mountpoint);
|
||||
if (hyper_create_file(mountpoint) < 0) {
|
||||
perror("create volume file failed");
|
||||
return -1;
|
||||
|
||||
+16
@@ -208,6 +208,21 @@ int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroup
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Trim all trailing '/' of a hyper_path except for the prefix one. */
|
||||
void hyper_filize(char *hyper_path)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (strlen(hyper_path) == 0)
|
||||
return;
|
||||
|
||||
p = &hyper_path[strlen(hyper_path) - 1];
|
||||
|
||||
for (; *p == '/' && p != hyper_path; p--) {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static int hyper_create_parent_dir(const char *hyper_path)
|
||||
{
|
||||
char *p, *path = strdup(hyper_path);
|
||||
@@ -225,6 +240,7 @@ static int hyper_create_parent_dir(const char *hyper_path)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* hyper_path must point to a file rather than a directory, e.g., having trailing '/' */
|
||||
int hyper_create_file(const char *hyper_path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@@ -26,6 +26,7 @@ void online_cpu(void);
|
||||
void online_memory(void);
|
||||
int hyper_cmd(char *cmd);
|
||||
int hyper_create_file(const char *hyper_path);
|
||||
void hyper_filize(char *hyper_path);
|
||||
int hyper_mkdir(char *path, mode_t mode);
|
||||
int hyper_open_channel(char *channel, int mode);
|
||||
int hyper_open_serial_dev(char *tty);
|
||||
|
||||
Reference in New Issue
Block a user