From 68a541498258949231e35544501e11c6003f2dce Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 29 Feb 2016 16:11:11 +0100 Subject: Make store implementations pluggable This for instance allows hydra-queue-runner to add the S3 backend at runtime. --- src/libstore/local-binary-cache-store.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/libstore/local-binary-cache-store.cc') diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index 5714688e02df..9fae80870ade 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -41,4 +41,13 @@ std::string LocalBinaryCacheStore::getFile(const std::string & path) return readFile(binaryCacheDir + "/" + path); } +static RegisterStoreImplementation regStore([](const std::string & uri) -> std::shared_ptr { + if (std::string(uri, 0, 7) != "file://") return 0; + auto store = std::make_shared(std::shared_ptr(0), + "", "", // FIXME: allow the signing key to be set + std::string(uri, 7)); + store->init(); + return store; +}); + } -- cgit 1.4.1 From 0402b6398d879889a621d60d049f8d81ac4ed86a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 29 Feb 2016 16:14:39 +0100 Subject: Eliminate local-binary-cache-store.hh --- src/libstore/local-binary-cache-store.cc | 26 +++++++++++++++++++++++++- src/libstore/local-binary-cache-store.hh | 31 ------------------------------- 2 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 src/libstore/local-binary-cache-store.hh (limited to 'src/libstore/local-binary-cache-store.cc') diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index 9fae80870ade..a10c9d1069d5 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -1,7 +1,31 @@ -#include "local-binary-cache-store.hh" +#include "binary-cache-store.hh" namespace nix { +class LocalBinaryCacheStore : public BinaryCacheStore +{ +private: + + Path binaryCacheDir; + +public: + + LocalBinaryCacheStore(std::shared_ptr localStore, + const Path & secretKeyFile, const Path & publicKeyFile, + const Path & binaryCacheDir); + + void init() override; + +protected: + + bool fileExists(const std::string & path) override; + + void upsertFile(const std::string & path, const std::string & data) override; + + std::string getFile(const std::string & path) override; + +}; + LocalBinaryCacheStore::LocalBinaryCacheStore(std::shared_ptr localStore, const Path & secretKeyFile, const Path & publicKeyFile, const Path & binaryCacheDir) diff --git a/src/libstore/local-binary-cache-store.hh b/src/libstore/local-binary-cache-store.hh deleted file mode 100644 index 0303ebe734a6..000000000000 --- a/src/libstore/local-binary-cache-store.hh +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "binary-cache-store.hh" - -namespace nix { - -class LocalBinaryCacheStore : public BinaryCacheStore -{ -private: - - Path binaryCacheDir; - -public: - - LocalBinaryCacheStore(std::shared_ptr localStore, - const Path & secretKeyFile, const Path & publicKeyFile, - const Path & binaryCacheDir); - - void init() override; - -protected: - - bool fileExists(const std::string & path) override; - - void upsertFile(const std::string & path, const std::string & data) override; - - std::string getFile(const std::string & path) override; - -}; - -} -- cgit 1.4.1 From 5a8455c85e35706a34892bea5b2a0c72f25663a1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 2 Mar 2016 18:21:48 +0100 Subject: Provide function required by Hydra --- src/libstore/local-binary-cache-store.cc | 14 +++++++++++--- src/libstore/store-api.hh | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/libstore/local-binary-cache-store.cc') diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index a10c9d1069d5..8590aea185d4 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -65,13 +65,21 @@ std::string LocalBinaryCacheStore::getFile(const std::string & path) return readFile(binaryCacheDir + "/" + path); } +ref openLocalBinaryCacheStore(std::shared_ptr localStore, + const Path & secretKeyFile, const Path & publicKeyFile, + const Path & binaryCacheDir) +{ + auto store = std::make_shared( + localStore, secretKeyFile, publicKeyFile, binaryCacheDir); + store->init(); + return ref(std::shared_ptr(store)); +} + static RegisterStoreImplementation regStore([](const std::string & uri) -> std::shared_ptr { if (std::string(uri, 0, 7) != "file://") return 0; - auto store = std::make_shared(std::shared_ptr(0), + return openLocalBinaryCacheStore(std::shared_ptr(0), "", "", // FIXME: allow the signing key to be set std::string(uri, 7)); - store->init(); - return store; }); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 97e834ed2bd8..9825d45db102 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -453,6 +453,11 @@ ref openStoreAt(const std::string & uri); ref openStore(); +ref openLocalBinaryCacheStore(std::shared_ptr localStore, + const Path & secretKeyFile, const Path & publicKeyFile, + const Path & binaryCacheDir); + + /* Store implementation registration. */ typedef std::function(const std::string & uri)> OpenStore; -- cgit 1.4.1