github.com/schwarzm/garden-linux@v0.0.0-20150507151835-33bca2147c47/integration/runner/tmpfs_mounter_linux.go (about)

     1  package runner
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  )
     7  
     8  func MustMountTmpfs(destination string) {
     9  	if _, err := os.Stat(destination); os.IsNotExist(err) {
    10  		must(os.MkdirAll(destination, 0755))
    11  		must(syscall.Mount("tmpfs", destination, "tmpfs", 0, ""))
    12  	}
    13  }
    14  
    15  func MustUnmountTmpfs(destination string) {
    16  	if _, err := os.Stat(destination); os.IsNotExist(err) {
    17  		return
    18  	}
    19  
    20  	for i := 0; i < 10; i++ {
    21  		syscall.Unmount(destination, syscall.MNT_DETACH)
    22  		os.Remove(destination)
    23  	}
    24  }
    25  
    26  func must(err error) {
    27  	if err != nil {
    28  		panic(err)
    29  	}
    30  }