Skip to content

Commit

Permalink
Remove addToStore variant as requested by FIXME
Browse files Browse the repository at this point in the history
The idea is it's always more flexible to consumer a `Source` than a
plain string, and it might even reduce memory consumption.

I also looked at `addToStoreFromDump` with its `// FIXME: remove?`, but
the worked needed for that is far more up for interpretation, so I
punted for now.
  • Loading branch information
Ericson2314 committed May 29, 2020
1 parent f60ce4f commit 66be7a7
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/libfetchers/tarball.cc
Expand Up @@ -71,7 +71,8 @@ DownloadFileResult downloadFile(
info.narHash = hashString(htSHA256, *sink.s);
info.narSize = sink.s->size();
info.ca = makeFixedOutputCA(FileIngestionMethod::Flat, hash);
store->addToStore(info, sink.s, NoRepair, NoCheckSigs);
auto source = StringSource { *sink.s };
store->addToStore(info, source, NoRepair, NoCheckSigs);
storePath = std::move(info.path);
}

Expand Down
10 changes: 7 additions & 3 deletions src/libstore/binary-cache-store.cc
Expand Up @@ -113,9 +113,11 @@ void BinaryCacheStore::writeNarInfo(ref<NarInfo> narInfo)
diskCache->upsertNarInfo(getUri(), hashPart, std::shared_ptr<NarInfo>(narInfo));
}

void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair, CheckSigsFlag checkSigs, std::shared_ptr<FSAccessor> accessor)
{
auto nar = make_ref<std::string>(narSource.drain());

if (!repair && isValidPath(info.path)) return;

/* Verify that all references are valid. This may do some .narinfo
Expand Down Expand Up @@ -347,7 +349,8 @@ StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath

ValidPathInfo info(makeFixedOutputPath(method, h, name));

addToStore(info, sink.s, repair, CheckSigs, nullptr);
auto source = StringSource { *sink.s };
addToStore(info, source, repair, CheckSigs, nullptr);

return std::move(info.path);
}
Expand All @@ -361,7 +364,8 @@ StorePath BinaryCacheStore::addTextToStore(const string & name, const string & s
if (repair || !isValidPath(info.path)) {
StringSink sink;
dumpString(s, sink);
addToStore(info, sink.s, repair, CheckSigs, nullptr);
auto source = StringSource { *sink.s };
addToStore(info, source, repair, CheckSigs, nullptr);
}

return std::move(info.path);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/binary-cache-store.hh
Expand Up @@ -74,7 +74,7 @@ public:
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
{ unsupported("queryPathFromHashPart"); }

void addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
void addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair, CheckSigsFlag checkSigs,
std::shared_ptr<FSAccessor> accessor) override;

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/export-import.cc
Expand Up @@ -100,7 +100,7 @@ StorePaths Store::importPaths(Source & source, std::shared_ptr<FSAccessor> acces
if (readInt(source) == 1)
readString(source);

addToStore(info, tee.source.data, NoRepair, checkSigs, accessor);
addToStore(info, tee.source, NoRepair, checkSigs, accessor);

res.push_back(info.path.clone());
}
Expand Down
15 changes: 0 additions & 15 deletions src/libstore/store-api.cc
Expand Up @@ -840,21 +840,6 @@ std::string makeFixedOutputCA(FileIngestionMethod recursive, const Hash & hash)
}


void Store::addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair, CheckSigsFlag checkSigs,
std::shared_ptr<FSAccessor> accessor)
{
addToStore(info, make_ref<std::string>(narSource.drain()), repair, checkSigs, accessor);
}

void Store::addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
RepairFlag repair, CheckSigsFlag checkSigs,
std::shared_ptr<FSAccessor> accessor)
{
StringSource source(*nar);
addToStore(info, source, repair, checkSigs, accessor);
}

}


Expand Down
7 changes: 1 addition & 6 deletions src/libstore/store-api.hh
Expand Up @@ -450,12 +450,7 @@ public:
/* Import a path into the store. */
virtual void addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs,
std::shared_ptr<FSAccessor> accessor = 0);

// FIXME: remove
virtual void addToStore(const ValidPathInfo & info, const ref<std::string> & nar,
RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs,
std::shared_ptr<FSAccessor> accessor = 0);
std::shared_ptr<FSAccessor> accessor = 0) = 0;

/* Copy the contents of a path to the store and register the
validity the resulting path. The resulting path is returned.
Expand Down
6 changes: 4 additions & 2 deletions src/nix/add-to-store.cc
Expand Up @@ -50,8 +50,10 @@ struct CmdAddToStore : MixDryRun, StoreCommand
info.narSize = sink.s->size();
info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);

if (!dryRun)
store->addToStore(info, sink.s);
if (!dryRun) {
auto source = StringSource { *sink.s };
store->addToStore(info, source);
}

logger->stdout("%s", store->printStorePath(info.path));
}
Expand Down

0 comments on commit 66be7a7

Please sign in to comment.