@@ -41,7 +41,7 @@ static int container_populate_volume(char *src, char *dest)
41
41
return -1 ;
42
42
}
43
43
44
- if (hyper_mkdir (dest , 0755 ) < 0 ) {
44
+ if (hyper_mkdir (dest , 0777 ) < 0 ) {
45
45
fprintf (stderr , "fail to create directroy %s\n" , dest );
46
46
return -1 ;
47
47
}
@@ -61,10 +61,18 @@ static int container_check_file_volume(char *hyper_path, const char **filename)
61
61
* filename = NULL ;
62
62
num = scandir (hyper_path , & list , NULL , NULL );
63
63
if (num < 0 ) {
64
+ /* No data in the volume yet, treat as non-file-volume */
65
+ if (errno == ENOENT ) {
66
+ return 0 ;
67
+ }
64
68
perror ("scan path failed" );
65
69
return -1 ;
66
70
} else if (num != 3 ) {
67
71
fprintf (stdout , "%s has %d files/dirs\n" , hyper_path , num - 2 );
72
+ for (i = 0 ; i < num ; i ++ ) {
73
+ free (list [i ]);
74
+ }
75
+ free (list );
68
76
return 0 ;
69
77
}
70
78
@@ -122,12 +130,6 @@ static int container_setup_volume(struct hyper_container *container)
122
130
}
123
131
124
132
sprintf (volume , "/%s/_data" , path );
125
- /* 0777 so that any user can write to new volumes */
126
- if (hyper_mkdir (volume , 0777 ) < 0 ) {
127
- fprintf (stderr , "fail to create directroy %s\n" , volume );
128
- return -1 ;
129
- }
130
-
131
133
if (container_check_file_volume (volume , & filevolume ) < 0 )
132
134
return -1 ;
133
135
@@ -142,6 +144,10 @@ static int container_setup_volume(struct hyper_container *container)
142
144
fprintf (stderr , "fail to populate volume %s\n" , mountpoint );
143
145
return -1 ;
144
146
}
147
+ } else if (hyper_mkdir (volume , 0777 ) < 0 ) {
148
+ /* First time mounting an empty volume */
149
+ perror ("create _data dir failed" );
150
+ return -1 ;
145
151
}
146
152
} else {
147
153
hyper_filize (mountpoint );
@@ -150,6 +156,11 @@ static int container_setup_volume(struct hyper_container *container)
150
156
return -1 ;
151
157
}
152
158
sprintf (volume , "/%s/_data/%s" , path , filevolume );
159
+ /* 0777 so that any user can read/write the new file volume */
160
+ if (chmod (volume , 0777 ) < 0 ) {
161
+ fprintf (stderr , "fail to chmod directroy %s\n" , volume );
162
+ return -1 ;
163
+ }
153
164
}
154
165
155
166
if (mount (volume , mountpoint , NULL , MS_BIND , NULL ) < 0 ) {
0 commit comments