// +build !windows,!plan9package shellimport ()// Returns a "run directory" for storing ephemeral files, which is guaranteed// to be only accessible to the current user.//// The path of the run directory is either $XDG_RUNTIME_DIR/elvish or// $tmpdir/elvish-$uid (where $tmpdir is the system temporary directory). The// former is used if the XDG_RUNTIME_DIR environment variable exists and the// latter directory does not exist.func () (string, error) { := getRunDirCandidates()for , := range {ifcheckExclusiveAccess() {return , nil } } := [0] := os.MkdirAll(, 0700)if != nil {return"", fmt.Errorf("mkdir: %v", ) }if !checkExclusiveAccess() {return"", fmt.Errorf("cannot create %v as a secure run directory", ) }return , nil}// Returns one or more candidates for the run directory, in descending order of// preference.func () []string { := filepath.Join(os.TempDir(), fmt.Sprintf("elvish-%d", os.Getuid()))ifos.Getenv(env.XDG_RUNTIME_DIR) != "" { := filepath.Join(os.Getenv(env.XDG_RUNTIME_DIR), "elvish")return []string{, } }return []string{}}func ( string) bool { , := os.Stat()if != nil {returnfalse } := .Sys().(*syscall.Stat_t)return .IsDir() && int(.Uid) == os.Getuid() && .Mode&077 == 0}
The pages are generated with Goldsv0.2.8-preview. (GOOS=darwin GOARCH=arm64)