From a5e78f08499084aa66b895c4e1a9840ef1ad27a9 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 8 Sep 2023 14:56:20 +0300 Subject: [PATCH] source/local: simplify feature file size checking --- source/local/local.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/source/local/local.go b/source/local/local.go index 041b4418f..a39fea9ea 100644 --- a/source/local/local.go +++ b/source/local/local.go @@ -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) @@ -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