mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Replace "XDG_RUNTIME_DIR" literals with a constant
This commit is contained in:
parent
e04c503431
commit
947ac39876
|
@ -7,6 +7,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/elves/elvish/pkg/util"
|
||||
)
|
||||
|
||||
// Returns a "run directory" for storing ephemeral files, which is guaranteed
|
||||
|
@ -38,8 +40,8 @@ func getSecureRunDir() (string, error) {
|
|||
// preference.
|
||||
func getRunDirCandidates() []string {
|
||||
tmpDirPath := filepath.Join(os.TempDir(), fmt.Sprintf("elvish-%d", os.Getuid()))
|
||||
if os.Getenv("XDG_RUNTIME_DIR") != "" {
|
||||
xdgDirPath := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "elvish")
|
||||
if os.Getenv(util.EnvXDG_RUNTIME_DIR) != "" {
|
||||
xdgDirPath := filepath.Join(os.Getenv(util.EnvXDG_RUNTIME_DIR), "elvish")
|
||||
return []string{xdgDirPath, tmpDirPath}
|
||||
}
|
||||
return []string{tmpDirPath}
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestGetSecureRunDir_PrefersTmpWhenOnlyItExists(t *testing.T) {
|
|||
func TestGetSecureRunDir_PrefersTmpWhenXdgEnvIsEmpty(t *testing.T) {
|
||||
_, tmp, cleanup := setupForSecureRunDir()
|
||||
defer cleanup()
|
||||
os.Setenv("XDG_RUNTIME_DIR", "")
|
||||
os.Setenv(util.EnvXDG_RUNTIME_DIR, "")
|
||||
testSecureRunDir(t, filepath.Join(tmp, elvishDashUid), false)
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,8 @@ func setupForSecureRunDir() (xdgRuntimeDir, tmpDir string, cleanup func()) {
|
|||
xdgRuntimeDir, xdgCleanup := util.TestDir()
|
||||
tmpDir, tmpCleanup := util.TestDir()
|
||||
envCleanup := withTempEnvs(map[string]string{
|
||||
"XDG_RUNTIME_DIR": xdgRuntimeDir,
|
||||
"TMPDIR": tmpDir,
|
||||
util.EnvXDG_RUNTIME_DIR: xdgRuntimeDir,
|
||||
"TMPDIR": tmpDir,
|
||||
})
|
||||
return xdgRuntimeDir, tmpDir, func() {
|
||||
envCleanup()
|
||||
|
|
|
@ -6,10 +6,11 @@ package util
|
|||
// Note that some of these env vars may be significant only in special
|
||||
// circumstances; such as when running unit tests.
|
||||
const (
|
||||
EnvHOME = "HOME"
|
||||
EnvPATH = "PATH"
|
||||
EnvPATHEXT = "PATHEXT"
|
||||
EnvPWD = "PWD"
|
||||
EnvSHLVL = "SHLVL"
|
||||
EnvLS_COLORS = "LS_COLORS"
|
||||
EnvHOME = "HOME"
|
||||
EnvPATH = "PATH"
|
||||
EnvPATHEXT = "PATHEXT"
|
||||
EnvPWD = "PWD"
|
||||
EnvSHLVL = "SHLVL"
|
||||
EnvLS_COLORS = "LS_COLORS"
|
||||
EnvXDG_RUNTIME_DIR = "XDG_RUNTIME_DIR"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user