mirror of
https://github.com/NixOS/nix
synced 2025-06-26 20:01:15 +02:00
HttpBinaryCacheStore: Improve error message for unauthorized caches
Instead of the unhelpful warning: 'https://cache.flakehub.com' does not appear to be a binary cache you now get warning: unable to download 'https://cache.flakehub.com/nix-cache-info': HTTP error 401 response body: {"code":401,"error":"Unauthorized","message":"Unauthorized."}
This commit is contained in:
parent
ff00eebb16
commit
3b21ea40cc
3 changed files with 29 additions and 5 deletions
|
@ -39,15 +39,13 @@ BinaryCacheStore::BinaryCacheStore(const Params & params)
|
|||
|
||||
void BinaryCacheStore::init()
|
||||
{
|
||||
std::string cacheInfoFile = "nix-cache-info";
|
||||
|
||||
auto cacheInfo = getFile(cacheInfoFile);
|
||||
auto cacheInfo = getNixCacheInfo();
|
||||
if (!cacheInfo) {
|
||||
upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n", "text/x-nix-cache-info");
|
||||
} else {
|
||||
for (auto & line : tokenizeString<Strings>(*cacheInfo, "\n")) {
|
||||
size_t colon= line.find(':');
|
||||
if (colon ==std::string::npos) continue;
|
||||
size_t colon = line.find(':');
|
||||
if (colon == std::string::npos) continue;
|
||||
auto name = line.substr(0, colon);
|
||||
auto value = trim(line.substr(colon + 1, std::string::npos));
|
||||
if (name == "StoreDir") {
|
||||
|
@ -63,6 +61,11 @@ void BinaryCacheStore::init()
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> BinaryCacheStore::getNixCacheInfo()
|
||||
{
|
||||
return getFile(cacheInfoFile);
|
||||
}
|
||||
|
||||
void BinaryCacheStore::upsertFile(const std::string & path,
|
||||
std::string && data,
|
||||
const std::string & mimeType)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue