Skip to content

Commit

Permalink
Add SkipEmpty FilterFn
Browse files Browse the repository at this point in the history
The FsReadCloser claimed to implictly skip empty files, but this was
only true when the final file to be read was empty. This updates to add
a SkipEmpty option that will filter out empty files before even
attempting to read file contents.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
  • Loading branch information
hasheddan committed Dec 8, 2020
1 parent 96e0fce commit 2d0e327
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/parser/fsreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func SkipDirs() FilterFn {
}
}

// SkipEmpty skips empty files.
func SkipEmpty() FilterFn {
return func(path string, info os.FileInfo) (bool, error) {
return info.Size() == 0, nil
}
}

// SkipNotYAML skips files that do not have YAML extension.
func SkipNotYAML() FilterFn {
return func(path string, info os.FileInfo) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestParser(t *testing.T) {
"FsBackendSkip": {
reason: "should skip empty files and files without yaml extension",
parser: New(metaScheme, objScheme),
backend: NewFsBackend(emptyFs, FsDir("."), FsFilters(SkipDirs(), SkipNotYAML())),
backend: NewFsBackend(emptyFs, FsDir("."), FsFilters(SkipDirs(), SkipEmpty(), SkipNotYAML())),
pkg: NewPackage(),
},
}
Expand Down

0 comments on commit 2d0e327

Please sign in to comment.