Refactor wopAddToStore to make wopAddTextToStore obsolete

This commit is contained in:
Robert Hensing 2020-09-17 20:19:15 +02:00
parent e34fe47d0c
commit c602ebfb34
3 changed files with 53 additions and 42 deletions

View file

@ -526,12 +526,8 @@ std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string &
}
StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
FileIngestionMethod method, HashType hashType, RepairFlag repair)
StorePath RemoteStore::addCAToStore(Source & dump, const string & name, ContentAddressMethod caMethod, StorePathSet references)
{
if (repair) throw Error("repairing is not supported when adding to store through the Nix daemon");
StorePathSet references;
auto conn(getConnection());
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 25) {
@ -539,7 +535,7 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
conn->to
<< wopAddToStore
<< name
<< renderContentAddressMethod(FixedOutputHashMethod{ .fileIngestionMethod = method, .hashType = hashType });
<< renderContentAddressMethod(caMethod);
writeStorePaths(*this, conn->to, references);
conn.withFramedSink([&](Sink & sink) {
@ -552,12 +548,20 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
else {
if (repair) throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25");
std::visit(overloaded {
[&](TextHashMethod thm) -> void {
std::string s = dump.drain();
conn->to << wopAddTextToStore << name << s;
writeStorePaths(*this, conn->to, references);
conn.processStderr();
},
[&](FixedOutputHashMethod fohm) -> void {
conn->to
<< wopAddToStore
<< name
<< ((hashType == htSHA256 && method == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */
<< (method == FileIngestionMethod::Recursive ? 1 : 0)
<< printHashType(hashType);
<< ((fohm.hashType == htSHA256 && fohm.fileIngestionMethod == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */
<< (fohm.fileIngestionMethod == FileIngestionMethod::Recursive ? 1 : 0)
<< printHashType(fohm.hashType);
try {
conn->to.written = 0;
@ -565,7 +569,7 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
connections->incCapacity();
{
Finally cleanup([&]() { connections->decCapacity(); });
if (method == FileIngestionMethod::Recursive) {
if (fohm.fileIngestionMethod == FileIngestionMethod::Recursive) {
dump.drainInto(conn->to);
} else {
std::string contents = dump.drain();
@ -584,10 +588,20 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
throw;
}
}
}, caMethod);
return parseStorePath(readString(conn->from));
}
}
StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
FileIngestionMethod method, HashType hashType, RepairFlag repair)
{
if (repair) throw Error("repairing is not supported when adding to store through the Nix daemon");
StorePathSet references;
return addCAToStore(dump, name, FixedOutputHashMethod{ .fileIngestionMethod = method, .hashType = hashType }, references);
}
void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
RepairFlag repair, CheckSigsFlag checkSigs)
@ -646,13 +660,8 @@ StorePath RemoteStore::addTextToStore(const string & name, const string & s,
const StorePathSet & references, RepairFlag repair)
{
if (repair) throw Error("repairing is not supported when building through the Nix daemon");
auto conn(getConnection());
conn->to << wopAddTextToStore << name << s;
writeStorePaths(*this, conn->to, references);
conn.processStderr();
return parseStorePath(readString(conn->from));
StringSource source(s);
return addCAToStore(source, name, TextHashMethod{}, references);
}

View file

@ -63,6 +63,8 @@ public:
void querySubstitutablePathInfos(const StorePathCAMap & paths,
SubstitutablePathInfos & infos) override;
StorePath addCAToStore(Source & dump, const string & name, ContentAddressMethod caMethod, StorePathSet references);
StorePath addToStoreFromDump(Source & dump, const string & name,
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override;

View file

@ -18,7 +18,7 @@ typedef enum {
wopQueryReferences = 5, // obsolete
wopQueryReferrers = 6,
wopAddToStore = 7,
wopAddTextToStore = 8,
wopAddTextToStore = 8, // obsolete since 1.25, Nix 3.0. Use wopAddToStore
wopBuildPaths = 9,
wopEnsurePath = 10,
wopAddTempRoot = 11,