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

Method Close

lib/notebox.go:1249–1272  ·  view source on GitHub ↗

Close closes an open Notefile, decrementing its refcount and making it available for purging from memory if this is the last reference.

(ctx context.Context)

Source from the content-addressed store, hash-verified

1247// Close closes an open Notefile, decrementing its refcount and making it available
1248// for purging from memory if this is the last reference.
1249func (openfile *OpenNotefile) Close(ctx context.Context) (err error) {
1250
1251 // Defensive coding only
1252 openfile.sanityCheckOpenCount()
1253 if openfile.openCount == 0 {
1254 logError(ctx, "*** MISMATCHED OpenNotefile/CloseNotefile ***")
1255 return fmt.Errorf("notefile being closed without a matching open")
1256 }
1257
1258 // Drop the refcnt on our own storage
1259 atomic.AddInt32(&openfile.openCount, -1)
1260 openfile.closeTime = time.Now()
1261 if debugBox {
1262 logDebug(ctx, "After closefile of %s, close refcnt now %d", openfile.storage, openfile.openCount)
1263 }
1264
1265 // Checkpoint to make sure everything is up-to-date
1266 if !autoCheckpointStarted {
1267 err = openfile.box.checkpointNotefile(ctx, openfile)
1268 }
1269
1270 // Done
1271 return err
1272}
1273
1274func (openfile *OpenNotefile) sanityCheckOpenCount() {
1275 count := atomic.LoadInt32(&openfile.openCount)

Callers

nothing calls this directly

Calls 4

sanityCheckOpenCountMethod · 0.95
logErrorFunction · 0.85
logDebugFunction · 0.85
checkpointNotefileMethod · 0.80

Tested by

no test coverage detected