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

Commit 5ba9b25

Browse files
committed
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 <[email protected]>
1 parent da986b4 commit 5ba9b25

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/container.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static int container_setup_volume(struct hyper_container *container)
144144
}
145145
}
146146
} else {
147+
hyper_filize(mountpoint);
147148
if (hyper_create_file(mountpoint) < 0) {
148149
perror("create volume file failed");
149150
return -1;

src/util.c

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

211+
/* Trim all trailing '/' of a hyper_path except for the prefix one. */
212+
void hyper_filize(char *hyper_path)
213+
{
214+
char *p;
215+
216+
if (strlen(hyper_path) == 0)
217+
return;
218+
219+
p = &hyper_path[strlen(hyper_path) - 1];
220+
221+
for (; *p == '/' && p != hyper_path; p--) {
222+
*p = '\0';
223+
}
224+
}
225+
211226
static int hyper_create_parent_dir(const char *hyper_path)
212227
{
213228
char *p, *path = strdup(hyper_path);
@@ -225,6 +240,7 @@ static int hyper_create_parent_dir(const char *hyper_path)
225240
return ret;
226241
}
227242

243+
/* hyper_path must point to a file rather than a directory, e.g., having trailing '/' */
228244
int hyper_create_file(const char *hyper_path)
229245
{
230246
int fd;

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void online_cpu(void);
2626
void online_memory(void);
2727
int hyper_cmd(char *cmd);
2828
int hyper_create_file(const char *hyper_path);
29+
void hyper_filize(char *hyper_path);
2930
int hyper_mkdir(char *path, mode_t mode);
3031
int hyper_open_channel(char *channel, int mode);
3132
int hyper_open_serial_dev(char *tty);

0 commit comments

Comments
 (0)