1717package root
1818
1919import (
20+ "os"
2021 "path/filepath"
2122
2223 "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@@ -59,18 +60,24 @@ func (r *Driver) Libraries() lookup.Locator {
5960// If configSearchPaths is specified, these paths are used as absolute paths,
6061// otherwise, /etc and /usr/share are searched.
6162func (r * Driver ) Configs () lookup.Locator {
62- searchRoot := r .Root
63- searchPaths := []string {"/etc" , "/usr/share" }
63+ return lookup .NewFileLocator (r .configSearchOptions ()... )
64+ }
65+
66+ func (r * Driver ) configSearchOptions () []lookup.Option {
6467 if len (r .configSearchPaths ) > 0 {
65- searchRoot = "/"
66- searchPaths = normalizeSearchPaths (r .configSearchPaths ... )
68+ return []lookup.Option {
69+ lookup .WithLogger (r .logger ),
70+ lookup .WithRoot ("/" ),
71+ lookup .WithSearchPaths (normalizeSearchPaths (r .configSearchPaths ... )... ),
72+ }
6773 }
68-
69- return lookup .NewFileLocator (
74+ searchPaths := []string {"/etc" }
75+ searchPaths = append (searchPaths , xdgDataDirs ()... )
76+ return []lookup.Option {
7077 lookup .WithLogger (r .logger ),
71- lookup .WithRoot (searchRoot ),
78+ lookup .WithRoot (r . Root ),
7279 lookup .WithSearchPaths (searchPaths ... ),
73- )
80+ }
7481}
7582
7683// normalizeSearchPaths takes a list of paths and normalized these.
@@ -85,3 +92,13 @@ func normalizeSearchPaths(paths ...string) []string {
8592 }
8693 return normalized
8794}
95+
96+ // xdgDataDirs finds the paths as specified in the environment variable XDG_DATA_DIRS.
97+ // See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html.
98+ func xdgDataDirs () []string {
99+ if dirs , exists := os .LookupEnv ("XDG_DATA_DIRS" ); exists && dirs != "" {
100+ return normalizeSearchPaths (dirs )
101+ }
102+
103+ return []string {"/usr/local/share" , "/usr/share" }
104+ }
0 commit comments