gosync/tools/scanner.go

48 lines
986 B
Go
Raw Normal View History

2023-09-07 15:20:19 +02:00
package tools
import (
"io/fs"
"os"
"path/filepath"
"strconv"
"strings"
2023-09-07 15:20:19 +02:00
"time"
"velvettear/gosync/log"
"velvettear/gosync/settings"
)
var sourceFiles []string
// unexported function(s)
func getSourceFiles() []string {
timestamp := time.Now()
if settings.SourceIsRemote() {
2023-09-07 15:20:19 +02:00
} else {
source, _ := strings.CutSuffix(settings.Source, "/*")
stats, error := os.Stat(source)
if error != nil {
log.Error("encountered an error getting the stats for the source", error.Error())
}
if stats.IsDir() {
log.Info("scanning source...", source)
filepath.WalkDir(source, fillSourceFiles)
} else {
sourceFiles = append(sourceFiles, settings.Source)
}
2023-09-07 15:20:19 +02:00
}
log.InfoTimed("found "+strconv.Itoa(len(sourceFiles))+" source files", timestamp.UnixMilli())
2023-09-07 15:20:19 +02:00
return sourceFiles
}
func fillSourceFiles(path string, dir fs.DirEntry, err error) error {
if err != nil {
return err
}
if dir.IsDir() {
return nil
}
sourceFiles = append(sourceFiles, path)
return nil
}