elvish/store/data_dir.go

32 lines
706 B
Go
Raw Normal View History

2014-10-01 06:57:38 +08:00
package store
import (
"errors"
"os"
"github.com/elves/elvish/util"
2014-10-01 06:57:38 +08:00
)
2016-02-08 06:23:16 +08:00
// ErrEmptyHOME is the error returned by EnsureDataDir when the environmental
// variable HOME is empty.
var ErrEmptyHOME = errors.New("environment variable HOME is empty")
2014-10-01 06:57:38 +08:00
2015-02-25 04:53:34 +08:00
// EnsureDataDir ensures Elvish's data directory exists, creating it if
2014-10-01 06:57:38 +08:00
// necessary. It returns the path to the data directory (never with a
// trailing slash) and possible error.
func EnsureDataDir() (string, error) {
ddir, err := DataDir()
if err != nil {
return "", err
2014-10-01 06:57:38 +08:00
}
return ddir, os.MkdirAll(ddir, 0700)
}
func DataDir() (string, error) {
home, err := util.GetHome("")
if err != nil {
return "", err
}
return home + "/.elvish", nil
}