Coverage Report

Created: 2026-07-14 18:13

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
162
SequentialFile::~SequentialFile() = default;
16
17
16
RandomAccessFile::~RandomAccessFile() = default;
18
19
900k
WritableFile::~WritableFile() = default;
20
21
450k
Logger::~Logger() = default;
22
23
450k
FileLock::~FileLock() = default;
24
25
145
void Log(Logger* info_log, const char* format, ...) {
26
145
  if (info_log != nullptr) {
  Branch (26:7): [True: 145, False: 0]
27
145
    va_list ap;
28
145
    va_start(ap, format);
29
145
    info_log->Logv(format, ap);
30
145
    va_end(ap);
31
145
  }
32
145
}
33
34
static Status DoWriteStringToFile(Env* env, const Slice& data,
35
162
                                  const std::string& fname, bool should_sync) {
36
162
  WritableFile* file;
37
162
  Status s = env->NewWritableFile(fname, &file);
38
162
  if (!s.ok()) {
  Branch (38:7): [True: 0, False: 162]
39
0
    return s;
40
0
  }
41
162
  s = file->Append(data);
42
162
  if (s.ok() && should_sync) {
  Branch (42:7): [True: 162, False: 0]
  Branch (42:17): [True: 162, False: 0]
43
162
    s = file->Sync();
44
162
  }
45
162
  if (s.ok()) {
  Branch (45:7): [True: 162, False: 0]
46
162
    s = file->Close();
47
162
  }
48
162
  delete file;  // Will auto-close if we did not close above
49
162
  if (!s.ok()) {
  Branch (49:7): [True: 0, False: 162]
50
0
    env->DeleteFile(fname);
51
0
  }
52
162
  return s;
53
162
}
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
162
                             const std::string& fname) {
62
162
  return DoWriteStringToFile(env, data, fname, true);
63
162
}
64
65
81
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
66
81
  data->clear();
67
81
  SequentialFile* file;
68
81
  Status s = env->NewSequentialFile(fname, &file);
69
81
  if (!s.ok()) {
  Branch (69:7): [True: 0, False: 81]
70
0
    return s;
71
0
  }
72
81
  static const int kBufferSize = 8192;
73
81
  char* space = new char[kBufferSize];
74
162
  while (true) {
  Branch (74:10): [Folded - Ignored]
75
162
    Slice fragment;
76
162
    s = file->Read(kBufferSize, &fragment, space);
77
162
    if (!s.ok()) {
  Branch (77:9): [True: 0, False: 162]
78
0
      break;
79
0
    }
80
162
    data->append(fragment.data(), fragment.size());
81
162
    if (fragment.empty()) {
  Branch (81:9): [True: 81, False: 81]
82
81
      break;
83
81
    }
84
162
  }
85
81
  delete[] space;
86
81
  delete file;
87
81
  return s;
88
81
}
89
90
EnvWrapper::~EnvWrapper() {}
91
92
}  // namespace leveldb