MCPcopy Create free account
hub / github.com/blues/note / CheckpointNotefile

Method CheckpointNotefile

lib/notebox.go:1221–1245  ·  view source on GitHub ↗

CheckpointNotefile checkpoints an open Notefile to storage

(ctx context.Context, notefileID string)

Source from the content-addressed store, hash-verified

1219
1220// CheckpointNotefile checkpoints an open Notefile to storage
1221func (box *Notebox) CheckpointNotefile(ctx context.Context, notefileID string) (err error) {
1222
1223 // Find the specified Notefile, and exit if it doesn't exist
1224 boxfile := box.Notefile()
1225 boxfile.lock.RLock()
1226 xnote, found := boxfile.Notes[compositeNoteID(box.instance.endpointID, notefileID)]
1227 boxfile.lock.RUnlock()
1228 if !found {
1229 return fmt.Errorf(note.ErrNotefileNoExist+" checkpointing notefile: notefile does not exist: %s", notefileID)
1230 }
1231
1232 // See if the notefile is currently open, by using its storage object ID
1233 notefileBody := noteboxBodyFromJSON(xnote.GetBody())
1234 iv, present := box.instance.openfiles.Load(notefileBody.Notefile.Storage)
1235 if !present {
1236 return fmt.Errorf("checkpointing notefile: notefile isn't currently open: %s", notefileID)
1237 }
1238 openfile := iv.(*OpenNotefile)
1239
1240 // Checkpoint to make sure everything is up-to-date
1241 err = box.checkpointNotefile(ctx, openfile)
1242
1243 // Done
1244 return err
1245}
1246
1247// Close closes an open Notefile, decrementing its refcount and making it available
1248// for purging from memory if this is the last reference.

Callers

nothing calls this directly

Calls 5

NotefileMethod · 0.95
checkpointNotefileMethod · 0.95
compositeNoteIDFunction · 0.85
noteboxBodyFromJSONFunction · 0.85
GetBodyMethod · 0.80

Tested by

no test coverage detected