Skip to content

Commit

Permalink
Merge pull request #1351 from marquiz/devel/local-refactor
Browse files Browse the repository at this point in the history
source/local: simplify feature file size checking
  • Loading branch information
k8s-ci-robot authored Sep 8, 2023
2 parents bcdee7b + a5e78f0 commit b7aa0b2
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,23 +324,6 @@ func getFeaturesFromFiles() (map[string]string, error) {

for _, file := range files {
fileName := file.Name()

fileInfo, err := file.Info()
if err != nil {
klog.ErrorS(err, "failed to get file info", "fileName", fileName)
continue
}

fileSize := fileInfo.Size()
if fileSize > MaxFeatureFileSize {
klog.ErrorS(
fmt.Errorf("file size limit exceeded: %d bytes > %d bytes", fileSize, MaxFeatureFileSize),
"skipping too big feature file",
"fileName", fileName, "fileSize", fileSize,
)
continue
}

lines, err := getFileContent(fileName)
if err != nil {
klog.ErrorS(err, "failed to read file", "fileName", fileName)
Expand Down Expand Up @@ -374,6 +357,10 @@ func getFileContent(fileName string) ([][]byte, error) {
}

if filestat.Mode().IsRegular() {
if filestat.Size() > MaxFeatureFileSize {
return lines, fmt.Errorf("file size limit exceeded: %d bytes > %d bytes", filestat.Size(), MaxFeatureFileSize)
}

fileContent, err := os.ReadFile(path)

// Do not return any lines if an error occurred
Expand Down

0 comments on commit b7aa0b2

Please sign in to comment.