Skip to content

Commit

Permalink
Merge pull request #79 from klihub/fixes/missing-spec-dir
Browse files Browse the repository at this point in the history
pkg/cdi: don't abort scan on missing Spec dir.
  • Loading branch information
elezar authored Aug 23, 2022
2 parents baded62 + e7cbe91 commit 67e7ef7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 5 additions & 2 deletions pkg/cdi/spec-dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package cdi

import (
"errors"
"io/fs"
"os"
"path/filepath"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -79,6 +79,9 @@ func scanSpecDirs(dirs []string, scanFn scanSpecFunc) error {
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
// for initial stat failure Walk calls us with nil info
if info == nil {
if errors.Is(err, fs.ErrNotExist) {
return nil
}
return err
}
// first call from Walk is for dir itself, others we skip
Expand Down
8 changes: 1 addition & 7 deletions pkg/cdi/spec-dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ devices:
classes = map[string]string{}
}

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

if tc.files == nil {
require.Error(t, err)
require.True(t, os.IsNotExist(err))
return
}

require.Equal(t, tc.success, success)
require.Equal(t, tc.failure, failure)
require.Equal(t, tc.vendors, vendors)
Expand Down

0 comments on commit 67e7ef7

Please sign in to comment.