Skip to content

Commit 1d28508

Browse files
committed
fixup! Add cuda-compat hook to allow compat libs to be discovered
Signed-off-by: Evan Lezar <[email protected]>
1 parent c3ead8a commit 1d28508

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

cmd/nvidia-cdi-hook/cudacompat/cudacompat.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (m command) updateCUDACompatLibs(containerRoot root, cfg *options) error {
116116
return nil
117117
}
118118

119-
libs, err := containerRoot.glob(filepath.Join(cudaCompatPath, "libcuda.so.*.*"))
119+
libs, err := containerRoot.globFiles(filepath.Join(cudaCompatPath, "libcuda.so.*.*"))
120120
if err != nil {
121121
m.logger.Warningf("Failed to find CUDA compat library: %w", err)
122122
return nil
@@ -158,13 +158,34 @@ func (r root) hasPath(path string) bool {
158158
return true
159159
}
160160

161-
// glob matches the specified pattern in the root.
162-
func (r root) glob(pattern string) ([]string, error) {
161+
// globFiles matches the specified pattern in the root.
162+
// The files that match must be regular files.
163+
func (r root) globFiles(pattern string) ([]string, error) {
163164
patternPath, err := r.resolve(pattern)
164165
if err != nil {
165166
return nil, err
166167
}
167-
return filepath.Glob(patternPath)
168+
matches, err := filepath.Glob(patternPath)
169+
if err != nil {
170+
return nil, err
171+
}
172+
var files []string
173+
for _, match := range matches {
174+
info, err := os.Lstat(match)
175+
if err != nil {
176+
return nil, err
177+
}
178+
// Ignore symlinks.
179+
if info.Mode()&os.ModeSymlink != 0 {
180+
continue
181+
}
182+
// Ignore directories.
183+
if info.IsDir() {
184+
continue
185+
}
186+
files = append(files, match)
187+
}
188+
return files, nil
168189
}
169190

170191
// resolve returns the absolute path including root path.

0 commit comments

Comments
 (0)