@@ -53,9 +53,42 @@ func (m *Mounter) Mount(targetPath string, specString string) *Response {
5353 return NewFailResponse ("Failed to create v3io FUSE container" , err )
5454 }
5555
56+ if err := m .createDirs (spec , targetPath ); err != nil {
57+ return NewFailResponse ("Failed to create folders" , err )
58+ }
59+
5660 return NewSuccessResponse ("Successfully mounted" )
5761}
5862
63+ func (m * Mounter ) createDirs (spec Spec , targetPath string ) error {
64+ var dirsToCreate []DirToCreate
65+ if err := json .Unmarshal ([]byte (spec .DirsToCreate ), & dirsToCreate ); err != nil {
66+ return fmt .Errorf ("Failed to parse dirsToCreate [%s]: %s" , spec .DirsToCreate , err .Error ())
67+ }
68+ for _ , dir := range dirsToCreate {
69+ if strings .HasPrefix (dir .Name , "/" ) {
70+ return fmt .Errorf ("Only creation of relative path is supported (%s)" , dir .Name )
71+ }
72+ dirToCreate := fmt .Sprintf ("%s/%s" , targetPath , dir .Name )
73+
74+ _ , err := os .Stat (dirToCreate )
75+ if err == nil {
76+ journal .Debug (fmt .Sprintf ("Folder already exists: %s" , dirToCreate ))
77+ continue
78+ }
79+
80+ if ! os .IsNotExist (err ) {
81+ return fmt .Errorf ("Stat failed for folder [%s]: %s" , dirToCreate , err )
82+ }
83+
84+ if err := os .MkdirAll (dirToCreate , dir .Permissions ); err != nil {
85+ return fmt .Errorf ("Failed to create folder (path: %s, filemode: %o): %s" , dir .Name , dir .Permissions , err .Error ())
86+ }
87+ journal .Debug (fmt .Sprintf ("Created folder: %s" , dirToCreate ))
88+ }
89+ return nil
90+ }
91+
5992func (m * Mounter ) Unmount (targetPath string ) * Response {
6093 journal .Debug ("Unmounting" )
6194
0 commit comments