handleRelease decrements the ref count for a snapshot. The snapshot and its registries are only cleaned up when the ref count reaches zero.
(ctx context.Context, params *ReleaseParams)
| 972 | // handleRelease decrements the ref count for a snapshot. |
| 973 | // The snapshot and its registries are only cleaned up when the ref count reaches zero. |
| 974 | func (s *Session) handleRelease(ctx context.Context, params *ReleaseParams) (any, error) { |
| 975 | if params == nil || params.Snapshot == 0 { |
| 976 | return nil, fmt.Errorf("%w: empty handle", ErrClientError) |
| 977 | } |
| 978 | |
| 979 | s.snapshotsMu.Lock() |
| 980 | sd := s.snapshots[params.Snapshot] |
| 981 | if sd == nil { |
| 982 | s.snapshotsMu.Unlock() |
| 983 | return nil, fmt.Errorf("%w: snapshot %d not found", ErrClientError, params.Snapshot) |
| 984 | } |
| 985 | sd.refCount-- |
| 986 | if sd.refCount <= 0 { |
| 987 | delete(s.snapshots, params.Snapshot) |
| 988 | // Release the API session's ref on the project snapshot. |
| 989 | sd.snapshot.Deref(s.projectSession) |
| 990 | } |
| 991 | s.snapshotsMu.Unlock() |
| 992 | return true, nil |
| 993 | } |
| 994 | |
| 995 | // handleGetDefaultProjectForFile returns the default project for a given file, |
| 996 | // or nil if no project currently contains the file. |
no test coverage detected