optimizes deleting obsolete paths (#1734)

This commit is contained in:
Natalie Villasana 2019-04-10 11:26:12 -04:00 committed by GitHub
parent 1257ce2588
commit 311fd2227a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -221,7 +221,11 @@ func (db *DB) Migration() *migrate.Migration {
log.Warn("Empty path")
return nil
}
return db.DeleteObsolete(path)
err := db.DeleteObsolete(path)
if err != nil {
log.Warn("err deleting obsolete paths: ", zap.Error(err))
}
return nil
}),
},
},
@ -247,16 +251,14 @@ func (db *DB) DeleteObsolete(path string) (err error) {
return err
}
var errList errs.Group
// iterate thru files list
for _, f := range files {
if info, err := os.Stat(filepath.Join(path, f.Name())); err == nil && info.IsDir() && len(f.Name()) == 2 {
err = os.RemoveAll(filepath.Join(path, f.Name()))
if err != nil {
return err
}
if len(f.Name()) == 2 {
errList.Add(os.RemoveAll(filepath.Join(path, f.Name())))
}
}
return nil
return errList.Err()
}
// WriteBandwidthAllocToDB inserts bandwidth agreement into DB