LCOV - code coverage report
Current view: top level - pebble/internal/base - close_helper.go (source / functions) Hit Total Coverage
Test: 2024-03-09 08:15Z 8df4320c - tests only.lcov Lines: 12 12 100.0 %
Date: 2024-03-09 08:16:22 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : package base
       6             : 
       7             : import "io"
       8             : 
       9             : // CloseHelper wraps an io.Closer in a wrapper that ignores extra calls to
      10             : // Close. It is useful to ensure cleanup in error paths (using defer) without
      11             : // double-closing.
      12           1 : func CloseHelper(closer io.Closer) io.Closer {
      13           1 :         return &closeHelper{
      14           1 :                 Closer: closer,
      15           1 :         }
      16           1 : }
      17             : 
      18             : type closeHelper struct {
      19             :         Closer io.Closer
      20             : }
      21             : 
      22             : // Close the underlying Closer, unless it was already closed.
      23           1 : func (h *closeHelper) Close() error {
      24           1 :         closer := h.Closer
      25           1 :         if closer == nil {
      26           1 :                 return nil
      27           1 :         }
      28           1 :         h.Closer = nil
      29           1 :         return closer.Close()
      30             : }

Generated by: LCOV version 1.14