elvish/store/data_dir.go
Qi Xiao 34c0d96830 Query HOME consistently.
A bug with osutil.Getcwd was also fixed. This fixes #91.
2016-02-11 23:43:48 +01:00

25 lines
609 B
Go

package store
import (
"errors"
"os"
"github.com/elves/elvish/osutil"
)
// ErrEmptyHOME is the error returned by EnsureDataDir when the environmental
// variable HOME is empty.
var ErrEmptyHOME = errors.New("environment variable HOME is empty")
// EnsureDataDir ensures Elvish's data directory exists, creating it if
// necessary. It returns the path to the data directory (never with a
// trailing slash) and possible error.
func EnsureDataDir() (string, error) {
home, err := osutil.GetHome("")
if err != nil {
return "", err
}
ddir := home + "/.elvish"
return ddir, os.MkdirAll(ddir, 0700)
}