7#include <nlohmann/json_fwd.hpp>
72 const std::filesystem::path&
root()
const {
return root_; }
83 std::expected<std::filesystem::path, std::string>
resolve(std::string_view relPath)
const;
93 std::expected<std::vector<UserCacheFile>, std::string>
list()
const;
97 std::expected<std::vector<uint8_t>, std::string>
read(std::string_view relPath)
const;
104 std::expected<void, std::string>
write(std::string_view relPath, std::span<const uint8_t> data);
113 std::expected<bool, std::string>
remove(std::string_view relPath);
133 void retain(std::string relPath);
139 bool isRetained(std::string_view relPath)
const;
142 std::filesystem::path root_;
144 std::set<std::string, std::less<>> retained_;
A flat, user-writable file store rooted at Motion Master's per-user cache directory.
Definition user_cache.h:65
std::expected< std::filesystem::path, std::string > resolve(std::string_view relPath) const
Validates relPath and maps it to an absolute path under the root.
Definition user_cache.cc:137
void retain(std::string relPath)
Marks a path as one this process holds open, so remove refuses it and list reports it as not deletabl...
Definition user_cache.cc:267
std::expected< std::vector< UserCacheFile >, std::string > list() const
Lists every file under the root, recursively.
Definition user_cache.cc:160
const std::filesystem::path & root() const
The cache root. Surfaced to users so they can find the files on disk themselves.
Definition user_cache.h:72
bool isRetained(std::string_view relPath) const
Whether retain covers relPath, and so will be refused by remove.
Definition user_cache.cc:269
std::expected< bool, std::string > remove(std::string_view relPath)
Removes a file, or a directory and everything under it.
Definition user_cache.cc:271
std::expected< void, std::string > write(std::string_view relPath, std::span< const uint8_t > data)
Writes (creating or replacing) a file, creating parent directories as needed.
Definition user_cache.cc:228
std::expected< std::vector< uint8_t >, std::string > read(std::string_view relPath) const
Reads a file's full contents.
Definition user_cache.cc:201
Definition http_server.h:25
void to_json(nlohmann::json &j, const SystemInfo &info)
Definition system_info.cc:301
One file in the user cache, as reported by UserCache::list.
Definition user_cache.h:17
uint64_t size
File size in bytes.
Definition user_cache.h:21
int64_t modifiedMs
Definition user_cache.h:22
bool deletable
Definition user_cache.h:25
std::string path
Definition user_cache.h:20