mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 19:27:58 +08:00
25 lines
525 B
Go
25 lines
525 B
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
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 := os.Getenv("HOME")
|
|
if home == "" {
|
|
return "", ErrEmptyHOME
|
|
}
|
|
home = strings.TrimRight(home, "/")
|
|
ddir := home + "/.elvish"
|
|
return ddir, os.MkdirAll(ddir, 0700)
|
|
}
|