MCPcopy Create free account
hub / github.com/baidu/tera / IsCacheFile

Method IsCacheFile

src/leveldb/persistent_cache/persistent_cache_impl.cc:46–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46bool PersistentCacheImpl::IsCacheFile(const std::string& file) {
47 // check if the file has .rc suffix
48 if (file.size() <= 3 || file.substr(file.size() - 3) != ".rc") {
49 return false;
50 }
51
52 std::string prefix = file.substr(0, file.size() - 3);
53 auto last_point_pos = prefix.find_last_of('.');
54 if (last_point_pos == std::string::npos) {
55 return false;
56 }
57
58 auto cache_id_str = prefix.substr(last_point_pos + 1);
59 uint64_t cache_id{0};
60 try {
61 cache_id = std::stoul(cache_id_str);
62 } catch (...) {
63 return false;
64 };
65
66 auto cache_file = metadata_.Lookup(cache_id);
67 if (!cache_file) {
68 return false;
69 }
70
71 bool is_same_path = false;
72
73 auto status = opt_.env->IsSamePath(file, cache_file->Path(), &is_same_path);
74 if (!status.ok()) {
75 LEVELDB_LOG("Error checking same path, path1 %s, path2 %s, reason %s, remove it.\n",
76 file.c_str(), cache_file->Path().c_str(), status.ToString().c_str());
77 return false;
78 }
79
80 return true;
81}
82
83PersistentCacheImpl::Statistics::Statistics()
84 : write_throughput(kWriteThroughput, {SubscriberType::THROUGHPUT}),

Callers

nothing calls this directly

Calls 6

sizeMethod · 0.45
LookupMethod · 0.45
IsSamePathMethod · 0.45
PathMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected