aboutsummaryrefslogtreecommitdiff
path: root/src/nix/prefetch.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/prefetch.cc')
-rw-r--r--src/nix/prefetch.cc77
1 files changed, 21 insertions, 56 deletions
diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc
index 969299489..ce8c85ecf 100644
--- a/src/nix/prefetch.cc
+++ b/src/nix/prefetch.cc
@@ -246,17 +246,15 @@ static int main_nix_prefetch_url(int argc, char * * argv)
static RegisterLegacyCommand r_nix_prefetch_url("nix-prefetch-url", main_nix_prefetch_url);
-struct CmdStorePrefetch : StoreCommand, MixJSON
+struct CmdStorePrefetchFile : StoreCommand, MixJSON
{
std::string url;
bool executable = false;
- bool unpack;
std::optional<std::string> name;
HashType hashType = htSHA256;
std::optional<Hash> expectedHash;
- CmdStorePrefetch(bool unpack)
- : unpack(unpack)
+ CmdStorePrefetchFile()
{
addFlag({
.longName = "name",
@@ -267,7 +265,7 @@ struct CmdStorePrefetch : StoreCommand, MixJSON
addFlag({
.longName = "expected-hash",
- .description = unpack ? "expected NAR hash of the unpacked tarball" : "expected hash of the file",
+ .description = "expected hash of the file",
.labels = {"hash"},
.handler = {[&](std::string s) {
expectedHash = Hash::parseAny(s, hashType);
@@ -276,43 +274,17 @@ struct CmdStorePrefetch : StoreCommand, MixJSON
addFlag(Flag::mkHashTypeFlag("hash-type", &hashType));
- expectArg("url", &url);
- }
-
- Category category() override { return catUtility; }
-
- void run(ref<Store> store) override
- {
- auto [storePath, hash] = prefetchFile(store, url, name, hashType, expectedHash, unpack, executable);
-
- if (json) {
- auto res = nlohmann::json::object();
- res["storePath"] = store->printStorePath(storePath);
- res["hash"] = hash.to_string(SRI, true);
- logger->cout(res.dump());
- } else {
- notice("Downloaded '%s' to '%s' (hash '%s').",
- url,
- store->printStorePath(storePath),
- hash.to_string(SRI, true));
- }
- }
-};
-
-struct CmdStorePrefetchFile : CmdStorePrefetch
-{
- CmdStorePrefetchFile()
- : CmdStorePrefetch(false)
- {
- name = "source";
-
addFlag({
.longName = "executable",
.description = "make the resulting file executable",
.handler = {&executable, true},
});
+
+ expectArg("url", &url);
}
+ Category category() override { return catUtility; }
+
std::string description() override
{
return "download a file into the Nix store";
@@ -324,29 +296,22 @@ struct CmdStorePrefetchFile : CmdStorePrefetch
#include "store-prefetch-file.md"
;
}
-};
-
-static auto rCmdStorePrefetchFile = registerCommand2<CmdStorePrefetchFile>({"store", "prefetch-file"});
-
-struct CmdStorePrefetchTarball : CmdStorePrefetch
-{
- CmdStorePrefetchTarball()
- : CmdStorePrefetch(true)
- {
- name = "source";
- }
-
- std::string description() override
+ void run(ref<Store> store) override
{
- return "download and unpack a tarball into the Nix store";
- }
+ auto [storePath, hash] = prefetchFile(store, url, name, hashType, expectedHash, false, executable);
- std::string doc() override
- {
- return
- #include "store-prefetch-tarball.md"
- ;
+ if (json) {
+ auto res = nlohmann::json::object();
+ res["storePath"] = store->printStorePath(storePath);
+ res["hash"] = hash.to_string(SRI, true);
+ logger->cout(res.dump());
+ } else {
+ notice("Downloaded '%s' to '%s' (hash '%s').",
+ url,
+ store->printStorePath(storePath),
+ hash.to_string(SRI, true));
+ }
}
};
-static auto rCmdStorePrefetchTarball = registerCommand2<CmdStorePrefetchTarball>({"store", "prefetch-tarball"});
+static auto rCmdStorePrefetchFile = registerCommand2<CmdStorePrefetchFile>({"store", "prefetch-file"});