MCPcopy Index your code
hub / github.com/dnote/dnote / prepareEmptyServerSync

Function prepareEmptyServerSync

pkg/cli/cmd/sync/sync.go:1075–1090  ·  view source on GitHub ↗

prepareEmptyServerSync marks all local books and notes as dirty when syncing to an empty server. This is typically used when switching to a new empty server but wanting to upload existing local data. Returns true if preparation was done, false otherwise.

(tx *database.DB)

Source from the content-addressed store, hash-verified

1073// This is typically used when switching to a new empty server but wanting to upload existing local data.
1074// Returns true if preparation was done, false otherwise.
1075func prepareEmptyServerSync(tx *database.DB) error {
1076 // Mark all books and notes as dirty and reset USN to 0
1077 if _, err := tx.Exec("UPDATE books SET usn = 0, dirty = 1 WHERE deleted = 0"); err != nil {
1078 return errors.Wrap(err, "marking books as dirty")
1079 }
1080 if _, err := tx.Exec("UPDATE notes SET usn = 0, dirty = 1 WHERE deleted = 0"); err != nil {
1081 return errors.Wrap(err, "marking notes as dirty")
1082 }
1083
1084 // Reset lastMaxUSN to 0 to match the server
1085 if err := updateLastMaxUSN(tx, 0); err != nil {
1086 return errors.Wrap(err, "resetting last max usn")
1087 }
1088
1089 return nil
1090}
1091
1092func newRun(ctx context.DnoteCtx) infra.RunEFunc {
1093 return func(cmd *cobra.Command, args []string) error {

Callers 2

newRunFunction · 0.85

Calls 2

updateLastMaxUSNFunction · 0.85
ExecMethod · 0.65

Tested by 1