cleanLocalNotes deletes from the local database any notes that are in invalid state judging by the full list of resources in the server. Concretely, the only acceptable situation in which a local note is not present in the server is if it is new and has not been uploaded (i.e. dirty and usn is 0). O
(tx *database.DB, fullList *syncList)
| 546 | // situation in which a local note is not present in the server is if it is new and has not been |
| 547 | // uploaded (i.e. dirty and usn is 0). Otherwise, it is a result of some kind of error and should be cleaned. |
| 548 | func cleanLocalNotes(tx *database.DB, fullList *syncList) error { |
| 549 | rows, err := tx.Query("SELECT uuid, usn, dirty FROM notes") |
| 550 | if err != nil { |
| 551 | return errors.Wrap(err, "getting local notes") |
| 552 | } |
| 553 | defer rows.Close() |
| 554 | |
| 555 | for rows.Next() { |
| 556 | var note database.Note |
| 557 | if err := rows.Scan(¬e.UUID, ¬e.USN, ¬e.Dirty); err != nil { |
| 558 | return errors.Wrap(err, "scanning a row for local note") |
| 559 | } |
| 560 | |
| 561 | ok := checkNoteInList(note.UUID, fullList) |
| 562 | if !ok && (!note.Dirty || note.USN != 0) { |
| 563 | err = note.Expunge(tx) |
| 564 | if err != nil { |
| 565 | return errors.Wrap(err, "expunging a note") |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | return nil |
| 571 | } |
| 572 | |
| 573 | // cleanLocalBooks deletes from the local database any books that are in invalid state |
| 574 | func cleanLocalBooks(tx *database.DB, fullList *syncList) error { |