1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

refactor: Don't re-construct SourcePath unnecessarily

This commit is contained in:
Robert Hensing 2024-12-13 18:46:47 +01:00 committed by Mic92
parent 91e91f62fa
commit c0b64f3377
2 changed files with 7 additions and 7 deletions

View file

@ -183,9 +183,9 @@ static void opAdd(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
for (auto & i : opArgs) { for (auto & i : opArgs) {
auto [accessor, canonPath] = PosixSourceAccessor::createAtRoot(i); auto sourcePath = PosixSourceAccessor::createAtRoot(i);
cout << fmt("%s\n", store->printStorePath(store->addToStore( cout << fmt("%s\n", store->printStorePath(store->addToStore(
std::string(baseNameOf(i)), {accessor, canonPath}))); std::string(baseNameOf(i)), sourcePath)));
} }
} }
@ -207,10 +207,10 @@ static void opAddFixed(Strings opFlags, Strings opArgs)
opArgs.pop_front(); opArgs.pop_front();
for (auto & i : opArgs) { for (auto & i : opArgs) {
auto [accessor, canonPath] = PosixSourceAccessor::createAtRoot(i); auto sourcePath = PosixSourceAccessor::createAtRoot(i);
std::cout << fmt("%s\n", store->printStorePath(store->addToStoreSlow( std::cout << fmt("%s\n", store->printStorePath(store->addToStoreSlow(
baseNameOf(i), baseNameOf(i),
{accessor, canonPath}, sourcePath,
method, method,
hashAlgo).path)); hashAlgo).path));
} }

View file

@ -37,13 +37,13 @@ struct CmdAddToStore : MixDryRun, StoreCommand
{ {
if (!namePart) namePart = baseNameOf(path); if (!namePart) namePart = baseNameOf(path);
auto [accessor, path2] = PosixSourceAccessor::createAtRoot(path); auto sourcePath = PosixSourceAccessor::createAtRoot(path);
auto storePath = dryRun auto storePath = dryRun
? store->computeStorePath( ? store->computeStorePath(
*namePart, {accessor, path2}, caMethod, hashAlgo, {}).first *namePart, sourcePath, caMethod, hashAlgo, {}).first
: store->addToStoreSlow( : store->addToStoreSlow(
*namePart, {accessor, path2}, caMethod, hashAlgo, {}).path; *namePart, sourcePath, caMethod, hashAlgo, {}).path;
logger->cout("%s", store->printStorePath(storePath)); logger->cout("%s", store->printStorePath(storePath));
} }