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 { namespace nix {
BinaryCacheStore::BinaryCacheStore(std::shared_ptr<Store> localStore, BinaryCacheStore::BinaryCacheStore(const StoreParams & params)
const StoreParams & params) : compression(get(params, "compression", "xz"))
: localStore(localStore)
, compression(get(params, "compression", "xz"))
{ {
auto secretKeyFile = get(params, "secret-key", ""); auto secretKeyFile = get(params, "secret-key", "");
if (secretKeyFile != "") if (secretKeyFile != "")
@ -170,30 +168,6 @@ std::shared_ptr<ValidPathInfo> BinaryCacheStore::queryPathInfoUncached(const Pat
return std::shared_ptr<NarInfo>(narInfo); 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, Path BinaryCacheStore::addToStore(const string & name, const Path & srcPath,
bool recursive, HashType hashAlgo, PathFilter & filter, bool repair) bool recursive, HashType hashAlgo, PathFilter & filter, bool repair)
{ {
@ -237,39 +211,6 @@ Path BinaryCacheStore::addTextToStore(const string & name, const string & s,
return info.path; 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 /* Given requests for a path /nix/store/<x>/<y>, this accessor will
first download the NAR for /nix/store/<x> from the binary cache, 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>. */ 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::unique_ptr<SecretKey> secretKey;
std::shared_ptr<Store> localStore;
std::string compression; std::string compression;
protected: protected:
BinaryCacheStore(std::shared_ptr<Store> localStore, BinaryCacheStore(const StoreParams & params);
const StoreParams & params);
[[noreturn]] void notImpl(); [[noreturn]] void notImpl();
@ -78,7 +75,8 @@ public:
{ return {}; } { return {}; }
void querySubstitutablePathInfos(const PathSet & paths, void querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos) override; SubstitutablePathInfos & infos)
{ }
void addToStore(const ValidPathInfo & info, const std::string & nar, void addToStore(const ValidPathInfo & info, const std::string & nar,
bool repair = false) override; bool repair = false) override;
@ -92,13 +90,15 @@ public:
void narFromPath(const Path & path, Sink & sink) override; 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, BuildResult buildDerivation(const Path & drvPath, const BasicDerivation & drv,
BuildMode buildMode = bmNormal) override BuildMode buildMode = bmNormal) override
{ notImpl(); } { notImpl(); }
void ensurePath(const Path & path) override; void ensurePath(const Path & path) override
{ notImpl(); }
void addTempRoot(const Path & path) override void addTempRoot(const Path & path) override
{ notImpl(); } { notImpl(); }

View file

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

View file

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

View file

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

View file

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