2023-09-07 15:20:19 +02:00
|
|
|
package tools
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2023-09-22 10:54:10 +02:00
|
|
|
"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()
|
2023-09-22 10:54:10 +02:00
|
|
|
if settings.SourceIsRemote() {
|
|
|
|
|
2023-09-07 15:20:19 +02:00
|
|
|
} else {
|
2023-09-22 10:54:10 +02:00
|
|
|
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
|
|
|
}
|
2023-09-22 10:54:10 +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
|
|
|
|
}
|