| 410 | } |
| 411 | |
| 412 | func syncDeleteNote(tx *database.DB, noteUUID string) error { |
| 413 | var localUSN int |
| 414 | var dirty bool |
| 415 | err := tx.QueryRow("SELECT usn, dirty FROM notes WHERE uuid = ?", noteUUID).Scan(&localUSN, &dirty) |
| 416 | if err != nil && err != sql.ErrNoRows { |
| 417 | return errors.Wrapf(err, "getting local note %s", noteUUID) |
| 418 | } |
| 419 | |
| 420 | // if note does not exist on client, noop |
| 421 | if err == sql.ErrNoRows { |
| 422 | return nil |
| 423 | } |
| 424 | |
| 425 | // if local copy is not dirty, delete |
| 426 | if !dirty { |
| 427 | _, err = tx.Exec("DELETE FROM notes WHERE uuid = ?", noteUUID) |
| 428 | if err != nil { |
| 429 | return errors.Wrapf(err, "deleting local note %s", noteUUID) |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | return nil |
| 434 | } |
| 435 | |
| 436 | // checkNotesPristine checks that none of the notes in the given book are dirty |
| 437 | func checkNotesPristine(tx *database.DB, bookUUID string) (bool, error) { |