github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/thirdparty/dir/dir.go (about) 1 package dir 2 3 // TODO move somewhere generic 4 5 import ( 6 "errors" 7 "os" 8 "path/filepath" 9 ) 10 11 // Writable ensures the directory exists and is writable 12 func Writable(path string) error { 13 // Construct the path if missing 14 if err := os.MkdirAll(path, os.ModePerm); err != nil { 15 return err 16 } 17 // Check the directory is writeable 18 if f, err := os.Create(filepath.Join(path, "._check_writeable")); err == nil { 19 os.Remove(f.Name()) 20 } else { 21 return errors.New("'" + path + "' is not writeable") 22 } 23 return nil 24 }