diff --git a/cue/load/fs.go b/cue/load/fs.go index 58681355dfd..8ec96dce3da 100644 --- a/cue/load/fs.go +++ b/cue/load/fs.go @@ -141,15 +141,6 @@ func (fs *fileSystem) makeAbs(path string) string { return filepath.Join(fs.cwd, path) } -func (fs *fileSystem) isDir(path string) bool { - path = fs.makeAbs(path) - if fs.getDir(path, false) != nil { - return true - } - fi, err := os.Stat(path) - return err == nil && fi.IsDir() -} - func (fs *fileSystem) readDir(path string) ([]iofs.DirEntry, errors.Error) { path = fs.makeAbs(path) m := fs.getDir(path, false) diff --git a/cue/load/import.go b/cue/load/import.go index 3f3895f2b83..536bbd1a8bc 100644 --- a/cue/load/import.go +++ b/cue/load/import.go @@ -18,6 +18,7 @@ import ( "cmp" "fmt" "io" + "io/fs" "os" pathpkg "path" "path/filepath" @@ -141,13 +142,17 @@ func (l *loader) importPkg(pos token.Pos, p *build.Instance) []*build.Instance { // since a package foo/bar/baz inherits from parent packages foo/bar and foo. // See https://cuelang.org/docs/concept/modules-packages-instances/#instances. for _, d := range dirs { - for dir := filepath.Clean(d[1]); ctxt.isDir(dir); { + dir := filepath.Clean(d[1]) + for { sd, ok := l.dirCachedBuildFiles[dir] if !ok { sd = l.scanDir(dir) l.dirCachedBuildFiles[dir] = sd } if err := sd.err; err != nil { + if errors.Is(err, fs.ErrNotExist) { + break + } return retErr(errors.Wrapf(err, token.NoPos, "import failed reading dir %v", dir)) } p.UnknownFiles = append(p.UnknownFiles, sd.unknownFiles...) @@ -208,7 +213,7 @@ func (l *loader) importPkg(pos token.Pos, p *build.Instance) []*build.Instance { func (l *loader) scanDir(dir string) cachedFileFiles { sd := cachedFileFiles{} files, err := l.cfg.fileSystem.readDir(dir) - if err != nil && !os.IsNotExist(err) { + if err != nil { sd.err = err return sd }