@@ -526,20 +526,16 @@ std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string &
526
526
}
527
527
528
528
529
- StorePath RemoteStore::addToStoreFromDump (Source & dump, const string & name,
530
- FileIngestionMethod method, HashType hashType, RepairFlag repair)
529
+ StorePath RemoteStore::addCAToStore (Source & dump, const string & name, ContentAddressMethod caMethod, StorePathSet references)
531
530
{
532
- if (repair) throw Error (" repairing is not supported when adding to store through the Nix daemon" );
533
- StorePathSet references;
534
-
535
531
auto conn (getConnection ());
536
532
537
533
if (GET_PROTOCOL_MINOR (conn->daemonVersion ) >= 25 ) {
538
534
539
535
conn->to
540
536
<< wopAddToStore
541
537
<< name
542
- << renderContentAddressMethod (FixedOutputHashMethod{ . fileIngestionMethod = method, . hashType = hashType } );
538
+ << renderContentAddressMethod (caMethod );
543
539
writeStorePaths (*this , conn->to , references);
544
540
545
541
conn.withFramedSink ([&](Sink & sink) {
@@ -552,42 +548,60 @@ StorePath RemoteStore::addToStoreFromDump(Source & dump, const string & name,
552
548
else {
553
549
if (repair) throw Error (" repairing is not supported when building through the Nix daemon protocol < 1.25" );
554
550
555
- conn->to
556
- << wopAddToStore
557
- << name
558
- << ((hashType == htSHA256 && method == FileIngestionMethod::Recursive) ? 0 : 1 ) /* backwards compatibility hack */
559
- << (method == FileIngestionMethod::Recursive ? 1 : 0 )
560
- << printHashType (hashType);
551
+ std::visit (overloaded {
552
+ [&](TextHashMethod thm) -> void {
553
+ std::string s = dump.drain ();
554
+ conn->to << wopAddTextToStore << name << s;
555
+ writeStorePaths (*this , conn->to , references);
556
+ conn.processStderr ();
557
+ },
558
+ [&](FixedOutputHashMethod fohm) -> void {
559
+ conn->to
560
+ << wopAddToStore
561
+ << name
562
+ << ((fohm.hashType == htSHA256 && fohm.fileIngestionMethod == FileIngestionMethod::Recursive) ? 0 : 1 ) /* backwards compatibility hack */
563
+ << (fohm.fileIngestionMethod == FileIngestionMethod::Recursive ? 1 : 0 )
564
+ << printHashType (fohm.hashType );
561
565
562
- try {
563
- conn->to .written = 0 ;
564
- conn->to .warn = true ;
565
- connections->incCapacity ();
566
- {
567
- Finally cleanup ([&]() { connections->decCapacity (); });
568
- if (method == FileIngestionMethod::Recursive) {
569
- dump.drainInto (conn->to );
570
- } else {
571
- std::string contents = dump.drain ();
572
- dumpString (contents, conn->to );
573
- }
574
- }
575
- conn->to .warn = false ;
576
- conn.processStderr ();
577
- } catch (SysError & e) {
578
- /* Daemon closed while we were sending the path. Probably OOM
579
- or I/O error. */
580
- if (e.errNo == EPIPE)
581
566
try {
567
+ conn->to .written = 0 ;
568
+ conn->to .warn = true ;
569
+ connections->incCapacity ();
570
+ {
571
+ Finally cleanup ([&]() { connections->decCapacity (); });
572
+ if (fohm.fileIngestionMethod == FileIngestionMethod::Recursive) {
573
+ dump.drainInto (conn->to );
574
+ } else {
575
+ std::string contents = dump.drain ();
576
+ dumpString (contents, conn->to );
577
+ }
578
+ }
579
+ conn->to .warn = false ;
582
580
conn.processStderr ();
583
- } catch (EndOfFile & e) { }
584
- throw ;
585
- }
581
+ } catch (SysError & e) {
582
+ /* Daemon closed while we were sending the path. Probably OOM
583
+ or I/O error. */
584
+ if (e.errNo == EPIPE)
585
+ try {
586
+ conn.processStderr ();
587
+ } catch (EndOfFile & e) { }
588
+ throw ;
589
+ }
586
590
591
+ }
592
+ }, caMethod);
587
593
return parseStorePath (readString (conn->from ));
588
594
}
589
595
}
590
596
597
+ StorePath RemoteStore::addToStoreFromDump (Source & dump, const string & name,
598
+ FileIngestionMethod method, HashType hashType, RepairFlag repair)
599
+ {
600
+ if (repair) throw Error (" repairing is not supported when adding to store through the Nix daemon" );
601
+ StorePathSet references;
602
+ return addCAToStore (dump, name, FixedOutputHashMethod{ .fileIngestionMethod = method, .hashType = hashType }, references);
603
+ }
604
+
591
605
592
606
void RemoteStore::addToStore (const ValidPathInfo & info, Source & source,
593
607
RepairFlag repair, CheckSigsFlag checkSigs)
@@ -646,13 +660,8 @@ StorePath RemoteStore::addTextToStore(const string & name, const string & s,
646
660
const StorePathSet & references, RepairFlag repair)
647
661
{
648
662
if (repair) throw Error (" repairing is not supported when building through the Nix daemon" );
649
-
650
- auto conn (getConnection ());
651
- conn->to << wopAddTextToStore << name << s;
652
- writeStorePaths (*this , conn->to , references);
653
-
654
- conn.processStderr ();
655
- return parseStorePath (readString (conn->from ));
663
+ StringSource source (s);
664
+ return addCAToStore (source, name, TextHashMethod{}, references);
656
665
}
657
666
658
667
0 commit comments