mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Merge pull request #425 from jmbaur/discover-use-xdg
Use XDG_DATA_DIRS instead of hardcoding /usr/share
This commit is contained in:
commit
7a9bc14d98
@ -17,6 +17,7 @@
|
|||||||
package root
|
package root
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
@ -59,18 +60,24 @@ func (r *Driver) Libraries() lookup.Locator {
|
|||||||
// If configSearchPaths is specified, these paths are used as absolute paths,
|
// If configSearchPaths is specified, these paths are used as absolute paths,
|
||||||
// otherwise, /etc and /usr/share are searched.
|
// otherwise, /etc and /usr/share are searched.
|
||||||
func (r *Driver) Configs() lookup.Locator {
|
func (r *Driver) Configs() lookup.Locator {
|
||||||
searchRoot := r.Root
|
return lookup.NewFileLocator(r.configSearchOptions()...)
|
||||||
searchPaths := []string{"/etc", "/usr/share"}
|
}
|
||||||
if len(r.configSearchPaths) > 0 {
|
|
||||||
searchRoot = "/"
|
|
||||||
searchPaths = normalizeSearchPaths(r.configSearchPaths...)
|
|
||||||
}
|
|
||||||
|
|
||||||
return lookup.NewFileLocator(
|
func (r *Driver) configSearchOptions() []lookup.Option {
|
||||||
|
if len(r.configSearchPaths) > 0 {
|
||||||
|
return []lookup.Option{
|
||||||
|
lookup.WithLogger(r.logger),
|
||||||
|
lookup.WithRoot("/"),
|
||||||
|
lookup.WithSearchPaths(normalizeSearchPaths(r.configSearchPaths...)...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchPaths := []string{"/etc"}
|
||||||
|
searchPaths = append(searchPaths, xdgDataDirs()...)
|
||||||
|
return []lookup.Option{
|
||||||
lookup.WithLogger(r.logger),
|
lookup.WithLogger(r.logger),
|
||||||
lookup.WithRoot(searchRoot),
|
lookup.WithRoot(r.Root),
|
||||||
lookup.WithSearchPaths(searchPaths...),
|
lookup.WithSearchPaths(searchPaths...),
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeSearchPaths takes a list of paths and normalized these.
|
// normalizeSearchPaths takes a list of paths and normalized these.
|
||||||
@ -85,3 +92,13 @@ func normalizeSearchPaths(paths ...string) []string {
|
|||||||
}
|
}
|
||||||
return normalized
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// xdgDataDirs finds the paths as specified in the environment variable XDG_DATA_DIRS.
|
||||||
|
// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html.
|
||||||
|
func xdgDataDirs() []string {
|
||||||
|
if dirs, exists := os.LookupEnv("XDG_DATA_DIRS"); exists && dirs != "" {
|
||||||
|
return normalizeSearchPaths(dirs)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{"/usr/local/share", "/usr/share"}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user