in packages/packages.go [106:141]
func NewFileSystemIndexer(logger *zap.Logger, paths ...string) *FileSystemIndexer {
walkerFn := func(basePath, path string, info os.DirEntry) (bool, error) {
relativePath, err := filepath.Rel(basePath, path)
if err != nil {
return false, err
}
dirs := strings.Split(relativePath, string(filepath.Separator))
if len(dirs) < 2 {
return false, nil // need to go to the package version level
}
if info.IsDir() {
versionDir := dirs[1]
_, err := semver.StrictNewVersion(versionDir)
if err != nil {
logger.Warn("ignoring unexpected directory",
zap.String("file.path", path))
return false, filepath.SkipDir
}
return true, nil
}
// Unexpected file, return nil in order to continue processing sibling directories
// Fixes an annoying problem when the .DS_Store file is left behind and the package
// is not loading without any error information
logger.Warn("ignoring unexpected file", zap.String("file.path", path))
return false, nil
}
return &FileSystemIndexer{
paths: paths,
label: "FileSystemIndexer",
walkerFn: walkerFn,
fsBuilder: ExtractedFileSystemBuilder,
logger: logger,
}
}