| 1247 | } |
| 1248 | |
| 1249 | static void write_cache_entry(const std::filesystem::path & path, const cache_entry & entry) |
| 1250 | { |
| 1251 | std::ofstream json{path / "index.json"}; |
| 1252 | json << "{\"filename\":" << json_string(entry.filename); |
| 1253 | json << ",\"size\":" << entry.size; |
| 1254 | |
| 1255 | // TODO get a timestamp for assets |
| 1256 | if (not entry.filename.starts_with("assets://")) |
| 1257 | { |
| 1258 | auto mtime = std::chrono::file_clock::to_sys(std::filesystem::last_write_time(entry.filename)); |
| 1259 | auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(mtime.time_since_epoch()).count(); |
| 1260 | auto size = entry.size; |
| 1261 | |
| 1262 | json << ",\"timestamp\":" << timestamp; |
| 1263 | } |
| 1264 | json << "}"; |
| 1265 | } |
| 1266 | |
| 1267 | // Returns false if the cache is out of date and must be deleted |
| 1268 | static bool check_cache_entry(const std::filesystem::path & path) |
no test coverage detected