gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/store/storedefs/data_dir.go (about)

     1  package storedefs
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  
     7  	"github.com/u-root/u-root/cmds/core/elvish/util"
     8  )
     9  
    10  // ErrEmptyHOME is the error returned by EnsureDataDir when the environmental
    11  // variable HOME is empty.
    12  var ErrEmptyHOME = errors.New("environment variable HOME is empty")
    13  
    14  // EnsureDataDir ensures Elvish's data directory exists, creating it if
    15  // necessary. It returns the path to the data directory (never with a
    16  // trailing slash) and possible error.
    17  func EnsureDataDir() (string, error) {
    18  	home, err := util.GetHome("")
    19  	if err != nil {
    20  		return "", err
    21  	}
    22  	ddir := home + "/.elvish"
    23  	return ddir, os.MkdirAll(ddir, 0700)
    24  }