Coverage Report

Created: 2025-07-23 07:17

/src/rocksdb/db/manifest_ops.cc
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) Meta Platforms, Inc. and affiliates.
2
//
3
//  This source code is licensed under both the GPLv2 (found in the
4
//  COPYING file in the root directory) and Apache 2.0 License
5
//  (found in the LICENSE.Apache file in the root directory).
6
7
#include "db/manifest_ops.h"
8
9
#include "file/filename.h"
10
11
namespace ROCKSDB_NAMESPACE {
12
13
Status GetCurrentManifestPath(const std::string& dbname, FileSystem* fs,
14
                              bool is_retry, std::string* manifest_path,
15
58.3k
                              uint64_t* manifest_file_number) {
16
58.3k
  assert(fs != nullptr);
17
58.3k
  assert(manifest_path != nullptr);
18
58.3k
  assert(manifest_file_number != nullptr);
19
20
58.3k
  IOOptions opts;
21
58.3k
  std::string fname;
22
58.3k
  if (is_retry) {
23
0
    opts.verify_and_reconstruct_read = true;
24
0
  }
25
58.3k
  Status s = ReadFileToString(fs, CurrentFileName(dbname), opts, &fname);
26
58.3k
  if (!s.ok()) {
27
0
    return s;
28
0
  }
29
58.3k
  if (fname.empty() || fname.back() != '\n') {
30
0
    return Status::Corruption("CURRENT file does not end with newline");
31
0
  }
32
  // remove the trailing '\n'
33
58.3k
  fname.resize(fname.size() - 1);
34
58.3k
  FileType type;
35
58.3k
  bool parse_ok = ParseFileName(fname, manifest_file_number, &type);
36
58.3k
  if (!parse_ok || type != kDescriptorFile) {
37
0
    return Status::Corruption("CURRENT file corrupted");
38
0
  }
39
58.3k
  *manifest_path = dbname;
40
58.3k
  if (dbname.back() != '/') {
41
58.3k
    manifest_path->push_back('/');
42
58.3k
  }
43
58.3k
  manifest_path->append(fname);
44
58.3k
  return Status::OK();
45
58.3k
}
46
47
}  // namespace ROCKSDB_NAMESPACE