LCOV - code coverage report
Current view: top level - pebble/internal/base - cleaner.go (source / functions) Hit Total Coverage
Test: 2023-10-07 08:16Z 803507a7 - tests only.lcov Lines: 17 23 73.9 %
Date: 2023-10-07 08:17:06 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2019 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 "github.com/cockroachdb/pebble/vfs"
       8             : 
       9             : // Cleaner cleans obsolete files.
      10             : type Cleaner interface {
      11             :         Clean(fs vfs.FS, fileType FileType, path string) error
      12             : }
      13             : 
      14             : // NeedsFileContents is implemented by a cleaner that needs the contents of the
      15             : // files that it is being asked to clean.
      16             : type NeedsFileContents interface {
      17             :         needsFileContents()
      18             : }
      19             : 
      20             : // DeleteCleaner deletes file.
      21             : type DeleteCleaner struct{}
      22             : 
      23             : // Clean removes file.
      24           1 : func (DeleteCleaner) Clean(fs vfs.FS, fileType FileType, path string) error {
      25           1 :         return fs.Remove(path)
      26           1 : }
      27             : 
      28           1 : func (DeleteCleaner) String() string {
      29           1 :         return "delete"
      30           1 : }
      31             : 
      32             : // ArchiveCleaner archives file instead delete.
      33             : type ArchiveCleaner struct{}
      34             : 
      35             : var _ NeedsFileContents = ArchiveCleaner{}
      36             : 
      37             : // Clean archives file.
      38           1 : func (ArchiveCleaner) Clean(fs vfs.FS, fileType FileType, path string) error {
      39           1 :         switch fileType {
      40           1 :         case FileTypeLog, FileTypeManifest, FileTypeTable:
      41           1 :                 destDir := fs.PathJoin(fs.PathDir(path), "archive")
      42           1 : 
      43           1 :                 if err := fs.MkdirAll(destDir, 0755); err != nil {
      44           0 :                         return err
      45           0 :                 }
      46             : 
      47           1 :                 destPath := fs.PathJoin(destDir, fs.PathBase(path))
      48           1 :                 return fs.Rename(path, destPath)
      49             : 
      50           0 :         default:
      51           0 :                 return fs.Remove(path)
      52             :         }
      53             : }
      54             : 
      55           1 : func (ArchiveCleaner) String() string {
      56           1 :         return "archive"
      57           1 : }
      58             : 
      59           0 : func (ArchiveCleaner) needsFileContents() {
      60           0 : }

Generated by: LCOV version 1.14