forked from lix-project/lix
Refactor wopAddToStore to make wopAddTextToStore obsolete
This commit is contained in:
parent
e34fe47d0c
commit
c602ebfb34
|
@ -526,12 +526,8 @@ std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string &
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
|
StorePath RemoteStore::addCAToStore(Source & dump, const string & name, ContentAddressMethod caMethod, StorePathSet references)
|
||||||
FileIngestionMethod method, HashType hashType, RepairFlag repair)
|
|
||||||
{
|
{
|
||||||
if (repair) throw Error("repairing is not supported when adding to store through the Nix daemon");
|
|
||||||
StorePathSet references;
|
|
||||||
|
|
||||||
auto conn(getConnection());
|
auto conn(getConnection());
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 25) {
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 25) {
|
||||||
|
@ -539,7 +535,7 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
|
||||||
conn->to
|
conn->to
|
||||||
<< wopAddToStore
|
<< wopAddToStore
|
||||||
<< name
|
<< name
|
||||||
<< renderContentAddressMethod(FixedOutputHashMethod{ .fileIngestionMethod = method, .hashType = hashType });
|
<< renderContentAddressMethod(caMethod);
|
||||||
writeStorePaths(*this, conn->to, references);
|
writeStorePaths(*this, conn->to, references);
|
||||||
|
|
||||||
conn.withFramedSink([&](Sink & sink) {
|
conn.withFramedSink([&](Sink & sink) {
|
||||||
|
@ -552,12 +548,20 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
|
||||||
else {
|
else {
|
||||||
if (repair) throw Error("repairing is not supported when building through the Nix daemon protocol < 1.25");
|
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
|
conn->to
|
||||||
<< wopAddToStore
|
<< wopAddToStore
|
||||||
<< name
|
<< name
|
||||||
<< ((hashType == htSHA256 && method == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */
|
<< ((fohm.hashType == htSHA256 && fohm.fileIngestionMethod == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */
|
||||||
<< (method == FileIngestionMethod::Recursive ? 1 : 0)
|
<< (fohm.fileIngestionMethod == FileIngestionMethod::Recursive ? 1 : 0)
|
||||||
<< printHashType(hashType);
|
<< printHashType(fohm.hashType);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn->to.written = 0;
|
conn->to.written = 0;
|
||||||
|
@ -565,7 +569,7 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
|
||||||
connections->incCapacity();
|
connections->incCapacity();
|
||||||
{
|
{
|
||||||
Finally cleanup([&]() { connections->decCapacity(); });
|
Finally cleanup([&]() { connections->decCapacity(); });
|
||||||
if (method == FileIngestionMethod::Recursive) {
|
if (fohm.fileIngestionMethod == FileIngestionMethod::Recursive) {
|
||||||
dump.drainInto(conn->to);
|
dump.drainInto(conn->to);
|
||||||
} else {
|
} else {
|
||||||
std::string contents = dump.drain();
|
std::string contents = dump.drain();
|
||||||
|
@ -584,10 +588,20 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}, caMethod);
|
||||||
return parseStorePath(readString(conn->from));
|
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,
|
void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
RepairFlag repair, CheckSigsFlag checkSigs)
|
RepairFlag repair, CheckSigsFlag checkSigs)
|
||||||
|
@ -646,13 +660,8 @@ StorePath RemoteStore::addTextToStore(const string & name, const string & s,
|
||||||
const StorePathSet & references, RepairFlag repair)
|
const StorePathSet & references, RepairFlag repair)
|
||||||
{
|
{
|
||||||
if (repair) throw Error("repairing is not supported when building through the Nix daemon");
|
if (repair) throw Error("repairing is not supported when building through the Nix daemon");
|
||||||
|
StringSource source(s);
|
||||||
auto conn(getConnection());
|
return addCAToStore(source, name, TextHashMethod{}, references);
|
||||||
conn->to << wopAddTextToStore << name << s;
|
|
||||||
writeStorePaths(*this, conn->to, references);
|
|
||||||
|
|
||||||
conn.processStderr();
|
|
||||||
return parseStorePath(readString(conn->from));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,8 @@ public:
|
||||||
void querySubstitutablePathInfos(const StorePathCAMap & paths,
|
void querySubstitutablePathInfos(const StorePathCAMap & paths,
|
||||||
SubstitutablePathInfos & infos) override;
|
SubstitutablePathInfos & infos) override;
|
||||||
|
|
||||||
|
StorePath addCAToStore(Source & dump, const string & name, ContentAddressMethod caMethod, StorePathSet references);
|
||||||
|
|
||||||
StorePath addToStoreFromDump(Source & dump, const string & name,
|
StorePath addToStoreFromDump(Source & dump, const string & name,
|
||||||
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override;
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) override;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ typedef enum {
|
||||||
wopQueryReferences = 5, // obsolete
|
wopQueryReferences = 5, // obsolete
|
||||||
wopQueryReferrers = 6,
|
wopQueryReferrers = 6,
|
||||||
wopAddToStore = 7,
|
wopAddToStore = 7,
|
||||||
wopAddTextToStore = 8,
|
wopAddTextToStore = 8, // obsolete since 1.25, Nix 3.0. Use wopAddToStore
|
||||||
wopBuildPaths = 9,
|
wopBuildPaths = 9,
|
||||||
wopEnsurePath = 10,
|
wopEnsurePath = 10,
|
||||||
wopAddTempRoot = 11,
|
wopAddTempRoot = 11,
|
||||||
|
|
Loading…
Reference in a new issue