mirror of
https://github.com/NixOS/nix
synced 2025-06-30 07:33:16 +02:00
Factor out commonality between nix-prefetch-url and nix-store --add-fixed
This commit is contained in:
parent
7f1a86d57c
commit
5dff49f661
6 changed files with 64 additions and 42 deletions
|
@ -186,23 +186,8 @@ static void opAddFixed(Strings opFlags, Strings opArgs)
|
|||
HashType hashAlgo = parseHashType(opArgs.front());
|
||||
opArgs.pop_front();
|
||||
|
||||
for (auto & i : opArgs) {
|
||||
auto hash = method == FileIngestionMethod::Recursive
|
||||
? hashPath(hashAlgo, i).first
|
||||
: hashFile(hashAlgo, i);
|
||||
auto [narHash, narSize] = hashPath(htSHA256, i);
|
||||
ValidPathInfo info(store->makeFixedOutputPath(method, hash, baseNameOf(i)));
|
||||
info.narHash = narHash;
|
||||
info.narSize = narSize;
|
||||
info.ca = FixedOutputHash { .method = method, .hash = hash };
|
||||
|
||||
auto source = sinkToSource([&](Sink & sink) {
|
||||
dumpPath(i, sink);
|
||||
});
|
||||
store->addToStore(info, *source);
|
||||
|
||||
std::cout << fmt("%s\n", store->printStorePath(info.path));
|
||||
}
|
||||
for (auto & i : opArgs)
|
||||
std::cout << fmt("%s\n", store->printStorePath(store->addToStoreSlow(baseNameOf(i), i, method, hashAlgo).path));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue