Skip to content

Commit e7cbe91

Browse files
committed
pkg/cdi: don't abort scan on missing Spec dir.
Ignore scanning errors related to missing Spec directories. This should fix errors where a missing directory (typically /etc/cdi) prevents the resolution of devices using files from subsequent configured directories. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent baded62 commit e7cbe91

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

pkg/cdi/spec-dirs.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
package cdi
1818

1919
import (
20+
"errors"
21+
"io/fs"
2022
"os"
2123
"path/filepath"
22-
23-
"github.com/pkg/errors"
2424
)
2525

2626
const (
@@ -79,6 +79,9 @@ func scanSpecDirs(dirs []string, scanFn scanSpecFunc) error {
7979
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
8080
// for initial stat failure Walk calls us with nil info
8181
if info == nil {
82+
if errors.Is(err, fs.ErrNotExist) {
83+
return nil
84+
}
8285
return err
8386
}
8487
// first call from Walk is for dir itself, others we skip

pkg/cdi/spec-dirs_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ devices:
186186
classes = map[string]string{}
187187
}
188188

189-
dirs := []string{dir}
189+
dirs := []string{"/no-such-dir", dir}
190190
err = scanSpecDirs(dirs, func(path string, prio int, spec *Spec, err error) error {
191191
name := filepath.Base(path)
192192
if err != nil {
@@ -202,12 +202,6 @@ devices:
202202
return nil
203203
})
204204

205-
if tc.files == nil {
206-
require.Error(t, err)
207-
require.True(t, os.IsNotExist(err))
208-
return
209-
}
210-
211205
require.Equal(t, tc.success, success)
212206
require.Equal(t, tc.failure, failure)
213207
require.Equal(t, tc.vendors, vendors)

0 commit comments

Comments
 (0)