| 494 | } |
| 495 | |
| 496 | func fullSyncBook(tx *database.DB, b client.SyncFragBook) error { |
| 497 | var localUSN int |
| 498 | var dirty bool |
| 499 | err := tx.QueryRow("SELECT usn, dirty FROM books WHERE uuid = ?", b.UUID).Scan(&localUSN, &dirty) |
| 500 | if err != nil && err != sql.ErrNoRows { |
| 501 | return errors.Wrapf(err, "getting local book %s", b.UUID) |
| 502 | } |
| 503 | |
| 504 | // if book exists in the server and does not exist in the client |
| 505 | if err == sql.ErrNoRows { |
| 506 | if e := mergeBook(tx, b, modeInsert); e != nil { |
| 507 | return errors.Wrapf(e, "resolving book") |
| 508 | } |
| 509 | } else if b.USN > localUSN { |
| 510 | if e := mergeBook(tx, b, modeUpdate); e != nil { |
| 511 | return errors.Wrapf(e, "resolving book") |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | return nil |
| 516 | } |
| 517 | |
| 518 | // checkNoteInList checks if the given syncList contains the note with the given uuid |
| 519 | func checkNoteInList(uuid string, list *syncList) bool { |