Coverage Report

Created: 2025-06-10 13:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/leveldb/util/env.cc
Line
Count
Source
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
0
Env::~Env() = default;
10
11
0
Status Env::NewAppendableFile(const std::string& fname, WritableFile** result) {
12
0
  return Status::NotSupported("NewAppendableFile", fname);
13
0
}
14
15
66.5k
SequentialFile::~SequentialFile() = default;
16
17
24
RandomAccessFile::~RandomAccessFile() = default;
18
19
166k
WritableFile::~WritableFile() = default;
20
21
33.2k
Logger::~Logger() = default;
22
23
33.2k
FileLock::~FileLock() = default;
24
25
33.3k
void Log(Logger* info_log, const char* format, ...) {
26
33.3k
  if (info_log != nullptr) {
  Branch (26:7): [True: 33.3k, False: 0]
27
33.3k
    va_list ap;
28
33.3k
    va_start(ap, format);
29
33.3k
    info_log->Logv(format, ap);
30
33.3k
    va_end(ap);
31
33.3k
  }
32
33.3k
}
33
34
static Status DoWriteStringToFile(Env* env, const Slice& data,
35
66.5k
                                  const std::string& fname, bool should_sync) {
36
66.5k
  WritableFile* file;
37
66.5k
  Status s = env->NewWritableFile(fname, &file);
38
66.5k
  if (!s.ok()) {
  Branch (38:7): [True: 0, False: 66.5k]
39
0
    return s;
40
0
  }
41
66.5k
  s = file->Append(data);
42
66.5k
  if (s.ok() && should_sync) {
  Branch (42:7): [True: 66.5k, False: 0]
  Branch (42:17): [True: 66.5k, False: 0]
43
66.5k
    s = file->Sync();
44
66.5k
  }
45
66.5k
  if (s.ok()) {
  Branch (45:7): [True: 66.5k, False: 0]
46
66.5k
    s = file->Close();
47
66.5k
  }
48
66.5k
  delete file;  // Will auto-close if we did not close above
49
66.5k
  if (!s.ok()) {
  Branch (49:7): [True: 0, False: 66.5k]
50
0
    env->DeleteFile(fname);
51
0
  }
52
66.5k
  return s;
53
66.5k
}
54
55
Status WriteStringToFile(Env* env, const Slice& data,
56
0
                         const std::string& fname) {
57
0
  return DoWriteStringToFile(env, data, fname, false);
58
0
}
59
60
Status WriteStringToFileSync(Env* env, const Slice& data,
61
66.5k
                             const std::string& fname) {
62
66.5k
  return DoWriteStringToFile(env, data, fname, true);
63
66.5k
}
64
65
33.2k
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
66
33.2k
  data->clear();
67
33.2k
  SequentialFile* file;
68
33.2k
  Status s = env->NewSequentialFile(fname, &file);
69
33.2k
  if (!s.ok()) {
  Branch (69:7): [True: 0, False: 33.2k]
70
0
    return s;
71
0
  }
72
33.2k
  static const int kBufferSize = 8192;
73
33.2k
  char* space = new char[kBufferSize];
74
66.5k
  while (true) {
  Branch (74:10): [Folded - Ignored]
75
66.5k
    Slice fragment;
76
66.5k
    s = file->Read(kBufferSize, &fragment, space);
77
66.5k
    if (!s.ok()) {
  Branch (77:9): [True: 0, False: 66.5k]
78
0
      break;
79
0
    }
80
66.5k
    data->append(fragment.data(), fragment.size());
81
66.5k
    if (fragment.empty()) {
  Branch (81:9): [True: 33.2k, False: 33.2k]
82
33.2k
      break;
83
33.2k
    }
84
66.5k
  }
85
33.2k
  delete[] space;
86
33.2k
  delete file;
87
33.2k
  return s;
88
33.2k
}
89
90
EnvWrapper::~EnvWrapper() {}
91
92
}  // namespace leveldb