Skip to content

Commit a4f58d9

Browse files
authored
GNSE-246: fix(sourcebundle): skip removed file paths in walk func (#110)
1 parent 0fe89e2 commit a4f58d9

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

sourcebundle/builder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,11 @@ func packagePrepareWalkFn(root string, ignoreRules *ignorefiles.Ruleset) filepat
687687
if err != nil {
688688
return fmt.Errorf("failed to remove ignored file %s: %s", relPath, err)
689689
}
690+
// Account for .terraformignore file rulesets that remove entire subtrees
691+
// in order to skip additional reads.
692+
if info.IsDir() {
693+
return filepath.SkipDir
694+
}
690695
return nil
691696
}
692697

sourcebundle/builder_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@ func TestBuilderTerraformIgnore(t *testing.T) {
519519
} else if !errors.Is(err, fs.ErrNotExist) {
520520
t.Errorf("excluded file exists but is not readable; should have been removed altogether")
521521
}
522+
523+
if _, err := os.Lstat(filepath.Join(localPkgDir, ".excluded")); err == nil {
524+
t.Errorf(".excluded dir exists; should have been removed")
525+
} else if !errors.Is(err, fs.ErrNotExist) {
526+
t.Errorf(".excluded dir exists but is not readable; should have been removed altogether")
527+
}
522528
}
523529

524530
func TestBuilderCoalescePackages(t *testing.T) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
excluded content
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
excluded
22
excluded-dir/
3+
.excluded

0 commit comments

Comments
 (0)