forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymlinkTargets.cpp
57 lines (47 loc) · 1.55 KB
/
SymlinkTargets.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "SymlinkTargets.h"
#include <string>
#include "FileSystem.h"
#include "Logging.h"
#include "ThreadPool.h"
#include "watchman_hash.h"
#include "watchman_scopeguard.h"
namespace watchman {
using Node = typename SymlinkTargetCache::Node;
bool SymlinkTargetCacheKey::operator==(
const SymlinkTargetCacheKey& other) const {
return otime.ticks == other.otime.ticks &&
relativePath == other.relativePath;
}
std::size_t SymlinkTargetCacheKey::hashValue() const {
return hash_128_to_64(w_string_hval(relativePath), otime.ticks);
}
SymlinkTargetCache::SymlinkTargetCache(
const w_string& rootPath,
size_t maxItems,
std::chrono::milliseconds errorTTL)
: cache_(maxItems, errorTTL), rootPath_(rootPath) {}
Future<std::shared_ptr<const Node>> SymlinkTargetCache::get(
const SymlinkTargetCacheKey& key) {
return cache_.get(
key, [this](const SymlinkTargetCacheKey& k) { return readLink(k); });
}
w_string SymlinkTargetCache::readLinkImmediate(
const SymlinkTargetCacheKey& key) const {
auto fullPath = w_string::pathCat({rootPath_, key.relativePath});
return readSymbolicLink(fullPath.c_str());
}
Future<w_string> SymlinkTargetCache::readLink(
const SymlinkTargetCacheKey& key) const {
return makeFuture(key)
.via(&getThreadPool())
.then([this](Result<SymlinkTargetCacheKey>&& key) {
return readLinkImmediate(key.value());
});
}
const w_string& SymlinkTargetCache::rootPath() const {
return rootPath_;
}
CacheStats SymlinkTargetCache::stats() const {
return cache_.stats();
}
} // namespace watchman