cleanLocalBooks deletes from the local database any books that are in invalid state
(tx *database.DB, fullList *syncList)
| 572 | |
| 573 | // cleanLocalBooks deletes from the local database any books that are in invalid state |
| 574 | func cleanLocalBooks(tx *database.DB, fullList *syncList) error { |
| 575 | rows, err := tx.Query("SELECT uuid, usn, dirty FROM books") |
| 576 | if err != nil { |
| 577 | return errors.Wrap(err, "getting local books") |
| 578 | } |
| 579 | defer rows.Close() |
| 580 | |
| 581 | for rows.Next() { |
| 582 | var book database.Book |
| 583 | if err := rows.Scan(&book.UUID, &book.USN, &book.Dirty); err != nil { |
| 584 | return errors.Wrap(err, "scanning a row for local book") |
| 585 | } |
| 586 | |
| 587 | ok := checkBookInList(book.UUID, fullList) |
| 588 | if !ok && (!book.Dirty || book.USN != 0) { |
| 589 | err = book.Expunge(tx) |
| 590 | if err != nil { |
| 591 | return errors.Wrap(err, "expunging a book") |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | return nil |
| 597 | } |
| 598 | |
| 599 | func fullSync(ctx context.DnoteCtx, tx *database.DB) error { |
| 600 | log.Debug("performing a full sync\n") |