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)
| 1247 | // Close closes an open Notefile, decrementing its refcount and making it available |
| 1248 | // for purging from memory if this is the last reference. |
| 1249 | func (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 | |
| 1274 | func (openfile *OpenNotefile) sanityCheckOpenCount() { |
| 1275 | count := atomic.LoadInt32(&openfile.openCount) |
nothing calls this directly
no test coverage detected