Skip to content

Commit f6e8310

Browse files
authored
Merge pull request #233 from moov-io/oss-skip-canceled-files-mapping
fix: skip canceled files in buildDirMapping
2 parents 586ea83 + 025d6b7 commit f6e8310

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

internal/pipeline/merging.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func (m *filesystemMerging) WithEachMerged(ctx context.Context, f func(context.C
336336
)
337337

338338
// Build a mapping of BatchHeader + EntryDetail from dir
339-
mappings, err := m.buildDirMapping(dir)
339+
mappings, err := m.buildDirMapping(dir, canceledFiles)
340340
if err != nil {
341341
el.Add(err)
342342
}
@@ -395,9 +395,11 @@ func fileAcceptor(canceledFiles []string) func(string) ach.FileAcceptance {
395395
}
396396
}
397397

398-
func (m *filesystemMerging) buildDirMapping(dir string) (*treemap.TreeMap[string, string], error) {
398+
func (m *filesystemMerging) buildDirMapping(dir string, canceledFiles []string) (*treemap.TreeMap[string, string], error) {
399399
tree := treemap.New[string, string]()
400400

401+
acceptor := fileAcceptor(canceledFiles)
402+
401403
err := fs.WalkDir(m.storage, dir, func(path string, d fs.DirEntry, err error) error {
402404
if err != nil {
403405
if strings.Contains(err.Error(), "is a directory") {
@@ -415,6 +417,11 @@ func (m *filesystemMerging) buildDirMapping(dir string) (*treemap.TreeMap[string
415417
return nil
416418
}
417419

420+
// Skip the file if merging would have skipped it
421+
if acceptor(path) == ach.SkipFile {
422+
return nil
423+
}
424+
418425
fd, err := m.storage.Open(path)
419426
if err != nil {
420427
return fmt.Errorf("opening %s failed: %w", path, err)

internal/pipeline/merging_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ func TestMerging_mappings(t *testing.T) {
165165
copyFile(t, filepath.Join("testdata", "ppd-debit4.ach"), filepath.Join(dir, "mergable", "ppd-debit4.ach"))
166166
copyFile(t, filepath.Join("testdata", "duplicate-trace.ach"), filepath.Join(dir, "mergable", "duplicate-trace.ach"))
167167

168+
// Canceled files
169+
err := os.WriteFile(filepath.Join(dir, "mergable", "foo2.ach"), nil, 0600)
170+
require.NoError(t, err)
171+
err = os.WriteFile(filepath.Join(dir, "mergable", "foo2.ach.canceled"), nil, 0600)
172+
require.NoError(t, err)
173+
168174
fs, err := storage.NewFilesystem(dir)
169175
require.NoError(t, err)
170176

@@ -184,7 +190,8 @@ func TestMerging_mappings(t *testing.T) {
184190
},
185191
}
186192

187-
mappings, err := m.buildDirMapping(".")
193+
canceledFiles := []string{"foo2.ach"}
194+
mappings, err := m.buildDirMapping(".", canceledFiles)
188195
require.NoError(t, err)
189196

190197
for it := mappings.Iterator(); it.Valid(); it.Next() {

0 commit comments

Comments
 (0)