LCOV - code coverage report
Current view: top level - src/leveldb/util - env.cc (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 85.7 % 49 42
Test Date: 2026-02-04 05:05:50 Functions: 60.0 % 20 12
Branches: 48.0 % 50 24

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
       2                 :             : // Use of this source code is governed by a BSD-style license that can be
       3                 :             : // found in the LICENSE file. See the AUTHORS file for names of contributors.
       4                 :             : 
       5                 :             : #include "leveldb/env.h"
       6                 :             : 
       7                 :             : namespace leveldb {
       8                 :             : 
       9                 :         374 : Env::~Env() = default;
      10                 :             : 
      11                 :           0 : Status Env::NewAppendableFile(const std::string& fname, WritableFile** result) {
      12         [ #  # ]:           0 :   return Status::NotSupported("NewAppendableFile", fname);
      13                 :             : }
      14                 :             : 
      15                 :        7463 : SequentialFile::~SequentialFile() = default;
      16                 :             : 
      17                 :        4143 : RandomAccessFile::~RandomAccessFile() = default;
      18                 :             : 
      19                 :       12804 : WritableFile::~WritableFile() = default;
      20                 :             : 
      21                 :        2846 : Logger::~Logger() = default;
      22                 :             : 
      23                 :        3316 : FileLock::~FileLock() = default;
      24                 :             : 
      25                 :       12137 : void Log(Logger* info_log, const char* format, ...) {
      26         [ +  - ]:       12137 :   if (info_log != nullptr) {
      27                 :       12137 :     va_list ap;
      28                 :       12137 :     va_start(ap, format);
      29                 :       12137 :     info_log->Logv(format, ap);
      30                 :       12137 :     va_end(ap);
      31                 :             :   }
      32                 :       12137 : }
      33                 :             : 
      34                 :        3941 : static Status DoWriteStringToFile(Env* env, const Slice& data,
      35                 :             :                                   const std::string& fname, bool should_sync) {
      36                 :        3941 :   WritableFile* file;
      37                 :        3941 :   Status s = env->NewWritableFile(fname, &file);
      38         [ +  - ]:        3941 :   if (!s.ok()) {
      39                 :             :     return s;
      40                 :             :   }
      41   [ +  -  -  + ]:        3941 :   s = file->Append(data);
      42   [ +  -  +  - ]:        3941 :   if (s.ok() && should_sync) {
      43   [ +  -  -  + ]:        3941 :     s = file->Sync();
      44                 :             :   }
      45         [ +  - ]:        3941 :   if (s.ok()) {
      46   [ +  -  -  + ]:        3941 :     s = file->Close();
      47                 :             :   }
      48         [ +  - ]:        3941 :   delete file;  // Will auto-close if we did not close above
      49         [ -  + ]:        3941 :   if (!s.ok()) {
      50         [ #  # ]:           0 :     env->DeleteFile(fname);
      51                 :             :   }
      52                 :             :   return s;
      53                 :           0 : }
      54                 :             : 
      55                 :           0 : Status WriteStringToFile(Env* env, const Slice& data,
      56                 :             :                          const std::string& fname) {
      57                 :           0 :   return DoWriteStringToFile(env, data, fname, false);
      58                 :             : }
      59                 :             : 
      60                 :        3941 : Status WriteStringToFileSync(Env* env, const Slice& data,
      61                 :             :                              const std::string& fname) {
      62                 :        3941 :   return DoWriteStringToFile(env, data, fname, true);
      63                 :             : }
      64                 :             : 
      65                 :        2854 : Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
      66                 :        2854 :   data->clear();
      67                 :        2854 :   SequentialFile* file;
      68                 :        2854 :   Status s = env->NewSequentialFile(fname, &file);
      69         [ +  - ]:        2854 :   if (!s.ok()) {
      70                 :             :     return s;
      71                 :             :   }
      72                 :        2854 :   static const int kBufferSize = 8192;
      73         [ +  - ]:        2854 :   char* space = new char[kBufferSize];
      74                 :        5708 :   while (true) {
      75         [ +  - ]:        5708 :     Slice fragment;
      76   [ +  -  -  + ]:        5708 :     s = file->Read(kBufferSize, &fragment, space);
      77         [ +  - ]:        5708 :     if (!s.ok()) {
      78                 :             :       break;
      79                 :             :     }
      80         [ +  - ]:        5708 :     data->append(fragment.data(), fragment.size());
      81         [ +  + ]:        5708 :     if (fragment.empty()) {
      82                 :             :       break;
      83                 :             :     }
      84                 :             :   }
      85         [ +  - ]:        2854 :   delete[] space;
      86         [ +  - ]:        2854 :   delete file;
      87                 :             :   return s;
      88                 :           0 : }
      89                 :             : 
      90                 :         374 : EnvWrapper::~EnvWrapper() {}
      91                 :             : 
      92                 :             : }  // namespace leveldb
        

Generated by: LCOV version 2.0-1