diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-07-10 12:51:56 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-07-10 12:51:56 +0200 |
commit | 7f1a86d57c548b4db44f589ffae2f6491d3b2d4c (patch) | |
tree | 4cc91443529612e59e897e85338be15204070941 /src/nix-store/nix-store.cc | |
parent | 06e3dd9005c1904a17a14a62dcd19813e2c261dc (diff) |
nix-store --add-fixed: Run in constant memory
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r-- | src/nix-store/nix-store.cc | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 7d81bf54f..c0274d4b6 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -174,10 +174,10 @@ static void opAdd(Strings opFlags, Strings opArgs) store. */ static void opAddFixed(Strings opFlags, Strings opArgs) { - auto recursive = FileIngestionMethod::Flat; + auto method = FileIngestionMethod::Flat; for (auto & i : opFlags) - if (i == "--recursive") recursive = FileIngestionMethod::Recursive; + if (i == "--recursive") method = FileIngestionMethod::Recursive; else throw UsageError("unknown flag '%1%'", i); if (opArgs.empty()) @@ -186,8 +186,23 @@ static void opAddFixed(Strings opFlags, Strings opArgs) HashType hashAlgo = parseHashType(opArgs.front()); opArgs.pop_front(); - for (auto & i : opArgs) - cout << fmt("%s\n", store->printStorePath(store->addToStore(std::string(baseNameOf(i)), i, recursive, hashAlgo))); + 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)); + } } |