ipld-eth-server/vendor/github.com/ipfs/go-ipfs/thirdparty/dir/dir.go
2019-12-02 13:24:46 -06:00

26 lines
518 B
Go

package dir
// TODO move somewhere generic
import (
"errors"
"os"
"path/filepath"
)
// Writable ensures the directory exists and is writable
func Writable(path string) error {
// Construct the path if missing
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
// Check the directory is writable
if f, err := os.Create(filepath.Join(path, "._check_writable")); err == nil {
f.Close()
os.Remove(f.Name())
} else {
return errors.New("'" + path + "' is not writable")
}
return nil
}