mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 01:47:51 +08:00
Export store.{ensureDataDir errEmptyHOME}
This commit is contained in:
parent
fd2e26700a
commit
f0c2bc11fb
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user