Treat $XDG_DATA_DIRS as semicolon-delimited on Windows.

This commit is contained in:
Qi Xiao 2022-06-19 14:41:25 +01:00
parent 2506b578b9
commit 6cb2fd3855
3 changed files with 8 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import (
"io"
"os"
"path/filepath"
"strings"
"src.elv.sh/pkg/daemon/daemondefs"
"src.elv.sh/pkg/env"
@ -50,9 +49,10 @@ func libPaths(w io.Writer) ([]string, error) {
}
if dataDirs := os.Getenv(env.XDG_DATA_DIRS); dataDirs != "" {
// We intentionally do not use filepath.SplitList and always follow the
// semantics of XDG, even on Windows.
for _, dataDir := range strings.Split(dataDirs, ":") {
// XDG requires the paths be joined with ":". However, on Windows ":"
// appear after the drive letter, so it's infeasible to use it to also
// join paths.
for _, dataDir := range filepath.SplitList(dataDirs) {
paths = append(paths, filepath.Join(dataDir, "elvish", "lib"))
}
} else {

View File

@ -53,7 +53,8 @@ func TestShell_LibPath_XDGPaths(t *testing.T) {
},
},
}, xdgDataDir2)
testutil.Setenv(t, env.XDG_DATA_DIRS, xdgDataDir1+":"+xdgDataDir2)
testutil.Setenv(t, env.XDG_DATA_DIRS,
xdgDataDir1+string(filepath.ListSeparator)+xdgDataDir2)
Test(t, &Program{},
ThatElvish("-c", "use a").WritesStdout("a from xdg-config-home\n"),

View File

@ -81,7 +81,8 @@ directories:
`%LocalAppData%\elvish\lib` (Windows) is searched.
3. If the `XDG_DATA_DIRS` environment variable is defined and non-empty, it is
treated as a colon-delimited list of paths, which are all searched.
treated as a colon-delimited list of paths (semicolon-delimited on Windows),
which are all searched.
Otherwise, `/usr/local/share/elvish/lib` and `/usr/share/elvish/lib` are
searched on non-Windows OSes. On Windows, no directories are searched.