diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-13 03:02:09 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-13 03:02:09 +0000 |
commit | c466cb2091b7a382aba1739c0320f2b6c0a04c1e (patch) | |
tree | 0532aad8e8753b046b1309ef6f8f646bc279ef03 /src/nix-prefetch-url | |
parent | 323d51a7a05d81c717d8e8673a78b07500a591fe (diff) | |
parent | 44157653850ce18536f837d7ed53521d61a238a1 (diff) |
Merge branch 'hash-always-has-type' into better-ca-parse-errors
Diffstat (limited to 'src/nix-prefetch-url')
-rw-r--r-- | src/nix-prefetch-url/nix-prefetch-url.cc | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index f752e0448..1001f27af 100644 --- a/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/src/nix-prefetch-url/nix-prefetch-url.cc @@ -153,14 +153,15 @@ static int _main(int argc, char * * argv) /* If an expected hash is given, the file may already exist in the store. */ - Hash hash(ht), expectedHash(ht); + std::optional<Hash> expectedHash; + Hash hash(ht); std::optional<StorePath> storePath; if (args.size() == 2) { expectedHash = Hash::parseAny(args[1], ht); const auto recursive = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat; - storePath = store->makeFixedOutputPath(recursive, expectedHash, name); + storePath = store->makeFixedOutputPath(recursive, *expectedHash, name); if (store->isValidPath(*storePath)) - hash = expectedHash; + hash = *expectedHash; else storePath.reset(); } @@ -200,22 +201,12 @@ static int _main(int argc, char * * argv) tmpFile = unpacked; } - /* FIXME: inefficient; addToStore() will also hash - this. */ - hash = unpack ? hashPath(ht, tmpFile).first : hashFile(ht, tmpFile); + const auto method = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat; - if (expectedHash != Hash(ht) && expectedHash != hash) - throw Error("hash mismatch for '%1%'", uri); - - const auto recursive = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat; - - /* Copy the file to the Nix store. FIXME: if RemoteStore - implemented addToStoreFromDump() and downloadFile() - supported a sink, we could stream the download directly - into the Nix store. */ - storePath = store->addToStore(name, tmpFile, recursive, ht); - - assert(*storePath == store->makeFixedOutputPath(recursive, hash, name)); + auto info = store->addToStoreSlow(name, tmpFile, method, ht, expectedHash); + storePath = info.path; + assert(info.ca); + hash = getContentAddressHash(*info.ca); } stopProgressBar(); |