forked from shosatojp/simplecache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.cpp
More file actions
23 lines (19 loc) · 686 Bytes
/
simple.cpp
File metadata and controls
23 lines (19 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "simple.hpp"
#include <iostream>
#include <string>
#include "entry.hpp"
bool ends_with(const std::string& src, const std::string& suffix) {
auto srclen = src.length(),
suffiexlen = suffix.length();
return srclen >= suffiexlen &&
src.compare(srclen - suffiexlen, suffiexlen, suffix) == 0;
}
SimpleCache::SimpleCache(const std::string& __cache_dir) {
for (const auto& file : fs::directory_iterator(__cache_dir)) {
std::string path = file.path();
if (ends_with(path, "_0")) {
const auto e = new SimpleCacheEntry(file.path());
index[e->get_key()] = std::unique_ptr<SimpleCacheEntry>(e);
}
}
}