Class thl::net::AssetStore#
-
class AssetStore#
A local store of verified, versioned assets.
Layout under the root:
The marker is written last and only after every file has been verified, so a directory without it is a partial install. Nothing knows what the files are for — models, sample packs, impulse responses are all the same to this class.<root>/<id>/<version>/<file names...> <root>/<id>/<version>/.tanh-installed
Installs are atomic in the sense that matters: a version is either complete and marked, or it is absent from installed(). A crash mid-download leaves a partial directory that the next install() or prune_partial() removes.
Not thread-safe. Drive one instance from one worker thread.
Public Functions
-
explicit AssetStore(std::filesystem::path root)#
rootis created if missing.
-
InstallResult install(const AssetDescriptor &descriptor, HttpClient &client, const AssetProgressFn &on_progress = {})#
Download, verify and mark a version installed.
Files already present and matching the descriptor are not fetched again, so a failed install resumes cheaply. An already-complete version returns Ok without touching the network.
-
bool is_installed(const std::string &id, const std::string &version) const#
True when the version is present, complete and marked.
-
std::filesystem::path path_for(const std::string &id, const std::string &version) const#
Directory for a version, whether or not it is installed.
Empty when the id or version is malformed.
-
std::vector<std::pair<std::string, std::string>> installed() const#
Every complete version present, as (id, version) pairs, sorted by id then version string.
Partial directories are skipped.
-
bool remove(const std::string &id, const std::string &version)#
Remove one version.
Returns false when it was not there or could not be deleted. Removing a version that is not installed still deletes a partial directory for it.
-
std::size_t prune_partial()#
Delete every unmarked version directory under the root.
Returns how many were removed. Worth calling at startup.
-
inline const std::filesystem::path &root() const#
Public Static Attributes
-
static constexpr const char *k_marker_name = ".tanh-installed"#
Name of the completion marker, exposed for tests and for tools that need to recognise the layout.
-
explicit AssetStore(std::filesystem::path root)#