sun::moon_bundling::MoonCache
class · Source (opens in a new tab)
class sun::moon_bundling::MoonCacheVerified download storage used by configured Moon and package dependencies.
Bundles are downloaded once with the system curl binary and stored under the cache directory, keyed by the URL. A cached bundle is reused forever, unless the config descriptor carries a hash (lowercase hex SHA-256 of the file bytes) that the cached file no longer matches — then it is fetched again and the fresh download must match the hash.
Public Functions
buildCurlCommand
public · function · static · Source (opens in a new tab)
std::string sun::moon_bundling::MoonCache::buildCurlCommand(const std::string &url, const std::filesystem::path &dest)The curl invocation fetch would run for url.
Exposed for tests.
defaultCacheDir
public · function · static · Source (opens in a new tab)
std::filesystem::path sun::moon_bundling::MoonCache::defaultCacheDir()~/.sun/cache/moons, or $SUN_MOON_CACHE when set; /tmp/sun-cache/moons when HOME is unset.
fetch
public · function · static · Source (opens in a new tab)
std::filesystem::path sun::moon_bundling::MoonCache::fetch(const std::string &url, const std::optional< std::string > &expectedHash, const std::filesystem::path &cacheDir=defaultCacheDir())Absolute path of the cached bundle for url, downloading on a cache miss or hash mismatch.
Throws SunError on a malformed URL, a failed download, or a hash mismatch on the fresh download.
Related: defaultCacheDir, SunError
setGithubToken
public · function · static · Source (opens in a new tab)
void sun::moon_bundling::MoonCache::setGithubToken(const std::string &token)Token for downloading private GitHub assets (gh-token).
Sent as an Authorization header, and only to GitHub hosts. When unset, the GH_TOKEN and GITHUB_TOKEN environment variables are used, in that order.
Related: Token
Private Functions
- computeFileSha256Hex
- computeSha256Hex
- downloadWithCurl
- getCachePathFor
- getGithubToken
- hasGithubHost
- validateUrl
computeFileSha256Hex
private · function · static · Source (opens in a new tab)
std::string sun::moon_bundling::MoonCache::computeFileSha256Hex(const std::filesystem::path &path)Reads a file and returns its hexadecimal SHA-256 digest.
computeSha256Hex
private · function · static · Source (opens in a new tab)
std::string sun::moon_bundling::MoonCache::computeSha256Hex(const std::string &content)Returns the hexadecimal SHA-256 digest of the supplied contents.
downloadWithCurl
private · function · static · Source (opens in a new tab)
void sun::moon_bundling::MoonCache::downloadWithCurl(const std::string &url, const std::filesystem::path &dest)Downloads a library to the destination path using curl.
getCachePathFor
private · function · static · Source (opens in a new tab)
std::filesystem::path sun::moon_bundling::MoonCache::getCachePathFor(const std::string &url, const std::filesystem::path &cacheDir)Derives the cache filename for the supplied library URL.
getGithubToken
private · function · static · Source (opens in a new tab)
std::string sun::moon_bundling::MoonCache::getGithubToken()Returns the GitHub authentication token.
hasGithubHost
private · function · static · Source (opens in a new tab)
bool sun::moon_bundling::MoonCache::hasGithubHost(const std::string &url)Reports whether this object has github host.
validateUrl
private · function · static · Source (opens in a new tab)
void sun::moon_bundling::MoonCache::validateUrl(const std::string &url)Checks whether a library download URL uses an accepted form.