fix(scanner): make sure we roll back invalid parents

fixes #402
This commit is contained in:
sentriz
2023-11-04 19:03:52 +00:00
parent 27b2d36376
commit ddb686bddc
2 changed files with 26 additions and 10 deletions

View File

@@ -231,17 +231,13 @@ func (s *Scanner) scanCallback(c *Context, absPath string, d fs.DirEntry, err er
log.Printf("processing folder %q", absPath)
tx := s.db.Begin()
if err := s.scanDir(tx, c, absPath); err != nil {
c.errs = append(c.errs, fmt.Errorf("%q: %w", absPath, err))
tx.Rollback()
return s.db.Transaction(func(tx *db.DB) error {
if err := s.scanDir(tx, c, absPath); err != nil {
c.errs = append(c.errs, fmt.Errorf("%q: %w", absPath, err))
return nil
}
return nil
}
if err := tx.Commit().Error; err != nil {
return fmt.Errorf("commit tx: %w", err)
}
return nil
})
}
func (s *Scanner) scanDir(tx *db.DB, c *Context, absPath string) error {