@@ -41,7 +41,7 @@ static int container_populate_volume(char *src, char *dest)
4141 return -1 ;
4242 }
4343
44- if (hyper_mkdir (dest , 0755 ) < 0 ) {
44+ if (hyper_mkdir (dest , 0777 ) < 0 ) {
4545 fprintf (stderr , "fail to create directroy %s\n" , dest );
4646 return -1 ;
4747 }
@@ -61,10 +61,18 @@ static int container_check_file_volume(char *hyper_path, const char **filename)
6161 * filename = NULL ;
6262 num = scandir (hyper_path , & list , NULL , NULL );
6363 if (num < 0 ) {
64+ /* No data in the volume yet, treat as non-file-volume */
65+ if (errno == ENOENT ) {
66+ return 0 ;
67+ }
6468 perror ("scan path failed" );
6569 return -1 ;
6670 } else if (num != 3 ) {
6771 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 );
6876 return 0 ;
6977 }
7078
@@ -122,12 +130,6 @@ static int container_setup_volume(struct hyper_container *container)
122130 }
123131
124132 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-
131133 if (container_check_file_volume (volume , & filevolume ) < 0 )
132134 return -1 ;
133135
@@ -142,6 +144,10 @@ static int container_setup_volume(struct hyper_container *container)
142144 fprintf (stderr , "fail to populate volume %s\n" , mountpoint );
143145 return -1 ;
144146 }
147+ } else if (hyper_mkdir (volume , 0777 ) < 0 ) {
148+ /* First time mounting an empty volume */
149+ perror ("create _data dir failed" );
150+ return -1 ;
145151 }
146152 } else {
147153 hyper_filize (mountpoint );
@@ -150,6 +156,11 @@ static int container_setup_volume(struct hyper_container *container)
150156 return -1 ;
151157 }
152158 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+ }
153164 }
154165
155166 if (mount (volume , mountpoint , NULL , MS_BIND , NULL ) < 0 ) {
0 commit comments