Skip to content

Commit

Permalink
getLocalFileList: filename check is now a callback
Browse files Browse the repository at this point in the history
  • Loading branch information
consolethinks committed Aug 26, 2024
1 parent 87bfc61 commit aeb06ec
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions datasetIngestor/getLocalFileList.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"runtime"
"strings"
"time"

"github.com/fatih/color"
)

type Datafile struct {
Expand Down Expand Up @@ -65,7 +63,7 @@ Returns:
The function logs an error and returns if it cannot change the working directory to the source folder.
*/
func GetLocalFileList(sourceFolder string, filelistingPath string, illegalFileNamesCounter *uint, symlinkCallback func(symlinkPath string, sourceFolder string) (bool, error)) (fullFileArray []Datafile, startTime time.Time, endTime time.Time, owner string, numFiles int64, totalSize int64, err error) {
func GetLocalFileList(sourceFolder string, filelistingPath string, symlinkCallback func(symlinkPath string, sourceFolder string) (bool, error), filenameCheckCallback func(filepath string) bool) (fullFileArray []Datafile, startTime time.Time, endTime time.Time, owner string, numFiles int64, totalSize int64, err error) {
// scan all lines
//fmt.Println("sourceFolder,listing:", sourceFolder, filelistingPath)
fullFileArray = make([]Datafile, 0)
Expand Down Expand Up @@ -163,27 +161,11 @@ func GetLocalFileList(sourceFolder string, filelistingPath string, illegalFileNa
}
}

// * filter invalid filenames *
// make sure that filenames do not contain characters like "\" or "*"
if strings.ContainsAny(modpath, "*\\") {
color.Set(color.FgRed)
log.Printf("Warning: the file %s contains illegal characters like *,\\ and will not be archived.", modpath)
color.Unset()
if illegalFileNamesCounter != nil {
*illegalFileNamesCounter++
}
keep = false
}
// and check for triple blanks, they are used to separate columns in messages
if keep && strings.Contains(modpath, " ") {
color.Set(color.FgRed)
log.Printf("Warning: the file %s contains 3 consecutive blanks which is not allowed. The file not be archived.", modpath)
color.Unset()
if illegalFileNamesCounter != nil {
*illegalFileNamesCounter++
}
keep = false
// filter invalid filenames if callback was set
if filenameCheckCallback != nil {
keep = keep && filenameCheckCallback(modpath)
}

if keep {
numFiles++
totalSize += f.Size()
Expand Down

0 comments on commit aeb06ec

Please sign in to comment.