Export store.{ensureDataDir errEmptyHOME}

This commit is contained in:
Cheer Xiao 2015-02-09 13:59:05 +01:00
parent fd2e26700a
commit f0c2bc11fb
2 changed files with 4 additions and 4 deletions

View File

@ -7,16 +7,16 @@ import (
) )
var ( var (
errEmptyHOME = errors.New("Environment variable HOME is empty") ErrEmptyHOME = errors.New("Environment variable HOME is empty")
) )
// ensureDataDir ensures Elvish's data directory exists, creating it if // ensureDataDir ensures Elvish's data directory exists, creating it if
// necessary. It returns the path to the data directory (never with a // necessary. It returns the path to the data directory (never with a
// trailing slash) and possible error. // trailing slash) and possible error.
func ensureDataDir() (string, error) { func EnsureDataDir() (string, error) {
home := os.Getenv("HOME") home := os.Getenv("HOME")
if home == "" { if home == "" {
return "", errEmptyHOME return "", ErrEmptyHOME
} }
home = strings.TrimRight(home, "/") home = strings.TrimRight(home, "/")
ddir := home + "/.elvish" ddir := home + "/.elvish"

View File

@ -16,7 +16,7 @@ var createTable = map[string]string{}
// DefaultDB returns the default database for storage. // DefaultDB returns the default database for storage.
func DefaultDB() (*sql.DB, error) { func DefaultDB() (*sql.DB, error) {
ddir, err := ensureDataDir() ddir, err := EnsureDataDir()
if err != nil { if err != nil {
return nil, err return nil, err
} }