From 83836672c90f9cdd3ec5164966682c1e9a99af13 Mon Sep 17 00:00:00 2001 From: timflannagan Date: Tue, 3 Aug 2021 12:41:39 -0400 Subject: [PATCH] internal/declcfg: Avoid processing the .indexignore file when walking the root fs Update internal/declcfg/load.go and avoid processing any files that are named `.indexignore` when walking the declarative config index root filesystem. When validating declarative config directories, the .indexignore file was being processed and validated. Signed-off-by: timflannagan --- internal/declcfg/load.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/declcfg/load.go b/internal/declcfg/load.go index a5cfca970..5bcb9df7d 100644 --- a/internal/declcfg/load.go +++ b/internal/declcfg/load.go @@ -17,6 +17,10 @@ import ( "github.com/operator-framework/operator-registry/internal/property" ) +const ( + indexIgnoreFilename = ".indexignore" +) + type WalkFunc func(path string, cfg *DeclarativeConfig, err error) error // WalkFS walks root using a gitignore-style filename matcher to skip files @@ -27,7 +31,7 @@ func WalkFS(root fs.FS, walkFn WalkFunc) error { if root == nil { return fmt.Errorf("no declarative config filesystem provided") } - matcher, err := ignore.NewMatcher(root, ".indexignore") + matcher, err := ignore.NewMatcher(root, indexIgnoreFilename) if err != nil { return err } @@ -36,7 +40,9 @@ func WalkFS(root fs.FS, walkFn WalkFunc) error { if err != nil { return walkFn(path, nil, err) } - if info.IsDir() || matcher.Match(path, false) { + // avoid validating a directory, an .indexignore file, or any file that matches + // an ignore pattern outlined in a .indexignore file. + if info.IsDir() || info.Name() == indexIgnoreFilename || matcher.Match(path, false) { return nil } file, err := root.Open(path)