github.com/schwarzm/garden-linux@v0.0.0-20150507151835-33bca2147c47/old/rootfs_provider/volume_creator.go (about)

     1  package rootfs_provider
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  )
     8  
     9  type VolumeCreator interface {
    10  	Create(root string, volume string) error
    11  }
    12  
    13  // SimpleVolumeCreator implements volume creation by (simply) creating the
    14  // relevant directories.  If a directory already exists in the image it is
    15  // emptied.
    16  type SimpleVolumeCreator struct{}
    17  
    18  func (SimpleVolumeCreator) Create(root string, volume string) error {
    19  	volumePath := filepath.Join(root, volume)
    20  
    21  	if info, err := os.Stat(volumePath); err == nil && !info.IsDir() {
    22  		return fmt.Errorf("volume creator: existing file at mount point: %v", volume)
    23  	}
    24  
    25  	if err := os.MkdirAll(volumePath, 0755); err != nil {
    26  		return fmt.Errorf("volume creator: creating volume directory: %v", err)
    27  	}
    28  
    29  	return nil
    30  }