Handle filepath.Walk errors (#351)

This commit is contained in:
Christian Muehlhaeuser 2020-11-12 23:29:17 +01:00 committed by GitHub
parent 00129c5942
commit 2c504eb8be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,9 +46,8 @@ func getAllFilesRecursive(baseDirectory string) (map[string][]os.FileInfo, error
var files = make(map[string][]os.FileInfo) var files = make(map[string][]os.FileInfo)
var directory string var directory string
filepath.Walk(baseDirectory, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(baseDirectory, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
log.Fatalf(err.Error())
return err return err
} }
@ -63,6 +62,11 @@ func getAllFilesRecursive(baseDirectory string) (map[string][]os.FileInfo, error
return nil return nil
}) })
if err != nil {
log.Fatalf(err.Error())
return nil, err
}
// Sort by date so we can delete old files // Sort by date so we can delete old files
for directory := range files { for directory := range files {
sort.Slice(files[directory], func(i, j int) bool { sort.Slice(files[directory], func(i, j int) bool {