CheckpointNotefile checkpoints an open Notefile to storage
(ctx context.Context, notefileID string)
| 1219 | |
| 1220 | // CheckpointNotefile checkpoints an open Notefile to storage |
| 1221 | func (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. |
nothing calls this directly
no test coverage detected