BinaryCacheStore: Remove buildPaths() / ensurePath()

This commit is contained in:
Eelco Dolstra 2016-05-04 20:15:41 +02:00
parent d593625d05
commit 3be2e71ab3
6 changed files with 20 additions and 83 deletions

View file

@ -14,10 +14,8 @@
namespace nix {
BinaryCacheStore::BinaryCacheStore(std::shared_ptr<Store> localStore,
const StoreParams & params)
: localStore(localStore)
, compression(get(params, "compression", "xz"))
BinaryCacheStore::BinaryCacheStore(const StoreParams & params)
: compression(get(params, "compression", "xz"))
{
auto secretKeyFile = get(params, "secret-key", "");
if (secretKeyFile != "")
@ -170,30 +168,6 @@ std::shared_ptr<ValidPathInfo> BinaryCacheStore::queryPathInfoUncached(const Pat
return std::shared_ptr<NarInfo>(narInfo);
}
void BinaryCacheStore::querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos)
{
PathSet left;
if (!localStore) return;
for (auto & storePath : paths) {
try {
auto info = localStore->queryPathInfo(storePath);
SubstitutablePathInfo sub;
sub.references = info->references;
sub.downloadSize = 0;
sub.narSize = info->narSize;
infos.emplace(storePath, sub);
} catch (InvalidPath &) {
left.insert(storePath);
}
}
if (settings.useSubstitutes)
localStore->querySubstitutablePathInfos(left, infos);
}
Path BinaryCacheStore::addToStore(const string & name, const Path & srcPath,
bool recursive, HashType hashAlgo, PathFilter & filter, bool repair)
{
@ -237,39 +211,6 @@ Path BinaryCacheStore::addTextToStore(const string & name, const string & s,
return info.path;
}
void BinaryCacheStore::buildPaths(const PathSet & paths, BuildMode buildMode)
{
for (auto & storePath : paths) {
assert(!isDerivation(storePath));
if (isValidPath(storePath)) continue;
if (!localStore)
throw Error(format("don't know how to realise path %1% in a binary cache") % storePath);
localStore->addTempRoot(storePath);
if (!localStore->isValidPath(storePath))
localStore->ensurePath(storePath);
auto info = localStore->queryPathInfo(storePath);
for (auto & ref : info->references)
if (ref != storePath)
ensurePath(ref);
StringSink sink;
dumpPath(storePath, sink);
addToStore(*info, *sink.s, buildMode == bmRepair);
}
}
void BinaryCacheStore::ensurePath(const Path & path)
{
buildPaths({path});
}
/* Given requests for a path /nix/store/<x>/<y>, this accessor will
first download the NAR for /nix/store/<x> from the binary cache,
build a NAR accessor for that NAR, and use that to access <y>. */

View file

@ -17,14 +17,11 @@ private:
std::unique_ptr<SecretKey> secretKey;
std::shared_ptr<Store> localStore;
std::string compression;
protected:
BinaryCacheStore(std::shared_ptr<Store> localStore,
const StoreParams & params);
BinaryCacheStore(const StoreParams & params);
[[noreturn]] void notImpl();
@ -78,7 +75,8 @@ public:
{ return {}; }
void querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos) override;
SubstitutablePathInfos & infos)
{ }
void addToStore(const ValidPathInfo & info, const std::string & nar,
bool repair = false) override;
@ -92,13 +90,15 @@ public:
void narFromPath(const Path & path, Sink & sink) override;
void buildPaths(const PathSet & paths, BuildMode buildMode = bmNormal) override;
void buildPaths(const PathSet & paths, BuildMode buildMode = bmNormal) override
{ notImpl(); }
BuildResult buildDerivation(const Path & drvPath, const BasicDerivation & drv,
BuildMode buildMode = bmNormal) override
{ notImpl(); }
void ensurePath(const Path & path) override;
void ensurePath(const Path & path) override
{ notImpl(); }
void addTempRoot(const Path & path) override
{ notImpl(); }

View file

@ -15,9 +15,9 @@ private:
public:
HttpBinaryCacheStore(std::shared_ptr<Store> localStore,
HttpBinaryCacheStore(
const StoreParams & params, const Path & _cacheUri)
: BinaryCacheStore(localStore, params)
: BinaryCacheStore(params)
, cacheUri(_cacheUri)
, downloaders(
std::numeric_limits<size_t>::max(),
@ -91,8 +91,7 @@ static RegisterStoreImplementation regStore([](
{
if (std::string(uri, 0, 7) != "http://" &&
std::string(uri, 0, 8) != "https://") return 0;
auto store = std::make_shared<HttpBinaryCacheStore>(std::shared_ptr<Store>(0),
params, uri);
auto store = std::make_shared<HttpBinaryCacheStore>(params, uri);
store->init();
return store;
});

View file

@ -11,9 +11,9 @@ private:
public:
LocalBinaryCacheStore(std::shared_ptr<Store> localStore,
LocalBinaryCacheStore(
const StoreParams & params, const Path & binaryCacheDir)
: BinaryCacheStore(localStore, params)
: BinaryCacheStore(params)
, binaryCacheDir(binaryCacheDir)
{
}
@ -90,8 +90,7 @@ static RegisterStoreImplementation regStore([](
-> std::shared_ptr<Store>
{
if (std::string(uri, 0, 7) != "file://") return 0;
auto store = std::make_shared<LocalBinaryCacheStore>(
std::shared_ptr<Store>(0), params, std::string(uri, 7));
auto store = std::make_shared<LocalBinaryCacheStore>(params, std::string(uri, 7));
store->init();
return store;
});

View file

@ -46,9 +46,9 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
Stats stats;
S3BinaryCacheStoreImpl(std::shared_ptr<Store> localStore,
S3BinaryCacheStoreImpl(
const StoreParams & params, const std::string & bucketName)
: S3BinaryCacheStore(localStore, params)
: S3BinaryCacheStore(params)
, bucketName(bucketName)
, config(makeConfig())
, client(make_ref<Aws::S3::S3Client>(*config))
@ -248,8 +248,7 @@ static RegisterStoreImplementation regStore([](
-> std::shared_ptr<Store>
{
if (std::string(uri, 0, 5) != "s3://") return 0;
auto store = std::make_shared<S3BinaryCacheStoreImpl>(std::shared_ptr<Store>(0),
params, std::string(uri, 5));
auto store = std::make_shared<S3BinaryCacheStoreImpl>(params, std::string(uri, 5));
store->init();
return store;
});

View file

@ -10,9 +10,8 @@ class S3BinaryCacheStore : public BinaryCacheStore
{
protected:
S3BinaryCacheStore(std::shared_ptr<Store> localStore,
const StoreParams & params)
: BinaryCacheStore(localStore, params)
S3BinaryCacheStore(const StoreParams & params)
: BinaryCacheStore(params)
{ }
public: