@@ -250,6 +250,20 @@ StorePath Store::addToStore(const string & name, const Path & _srcPath,
250
250
}
251
251
252
252
253
+ void Store::addMultipleToStore (
254
+ Source & source,
255
+ RepairFlag repair,
256
+ CheckSigsFlag checkSigs)
257
+ {
258
+ auto expected = readNum<uint64_t >(source);
259
+ for (uint64_t i = 0 ; i < expected; ++i) {
260
+ auto info = ValidPathInfo::read (source, *this , 16 );
261
+ info.ultimate = false ;
262
+ addToStore (info, source, repair, checkSigs);
263
+ }
264
+ }
265
+
266
+
253
267
/*
254
268
The aim of this function is to compute in one pass the correct ValidPathInfo for
255
269
the files that we are trying to add to the store. To accomplish that in one
@@ -771,6 +785,19 @@ const Store::Stats & Store::getStats()
771
785
}
772
786
773
787
788
+ static std::string makeCopyPathMessage (
789
+ std::string_view srcUri,
790
+ std::string_view dstUri,
791
+ std::string_view storePath)
792
+ {
793
+ return srcUri == " local" || srcUri == " daemon"
794
+ ? fmt (" copying path '%s' to '%s'" , storePath, dstUri)
795
+ : dstUri == " local" || dstUri == " daemon"
796
+ ? fmt (" copying path '%s' from '%s'" , storePath, srcUri)
797
+ : fmt (" copying path '%s' from '%s' to '%s'" , storePath, srcUri, dstUri);
798
+ }
799
+
800
+
774
801
void copyStorePath (
775
802
Store & srcStore,
776
803
Store & dstStore,
@@ -780,14 +807,10 @@ void copyStorePath(
780
807
{
781
808
auto srcUri = srcStore.getUri ();
782
809
auto dstUri = dstStore.getUri ();
783
-
810
+ auto storePathS = srcStore. printStorePath (storePath);
784
811
Activity act (*logger, lvlInfo, actCopyPath,
785
- srcUri == " local" || srcUri == " daemon"
786
- ? fmt (" copying path '%s' to '%s'" , srcStore.printStorePath (storePath), dstUri)
787
- : dstUri == " local" || dstUri == " daemon"
788
- ? fmt (" copying path '%s' from '%s'" , srcStore.printStorePath (storePath), srcUri)
789
- : fmt (" copying path '%s' from '%s' to '%s'" , srcStore.printStorePath (storePath), srcUri, dstUri),
790
- {srcStore.printStorePath (storePath), srcUri, dstUri});
812
+ makeCopyPathMessage (srcUri, dstUri, storePathS),
813
+ {storePathS, srcUri, dstUri});
791
814
PushActivity pact (act.id );
792
815
793
816
auto info = srcStore.queryPathInfo (storePath);
@@ -896,19 +919,31 @@ std::map<StorePath, StorePath> copyPaths(
896
919
for (auto & path : storePaths)
897
920
pathsMap.insert_or_assign (path, path);
898
921
899
- // FIXME: Temporary hack to copy closures in a single round-trip.
900
- if (dynamic_cast <RemoteStore *>(&dstStore)) {
901
- if (!missing.empty ()) {
902
- auto source = sinkToSource ([&](Sink & sink) {
903
- srcStore.exportPaths (missing, sink);
904
- });
905
- dstStore.importPaths (*source, NoCheckSigs);
922
+ Activity act (*logger, lvlInfo, actCopyPaths, fmt (" copying %d paths" , missing.size ()));
923
+
924
+ auto sorted = srcStore.topoSortPaths (missing);
925
+ std::reverse (sorted.begin (), sorted.end ());
926
+
927
+ auto source = sinkToSource ([&](Sink & sink) {
928
+ sink << sorted.size ();
929
+ for (auto & storePath : sorted) {
930
+ auto srcUri = srcStore.getUri ();
931
+ auto dstUri = dstStore.getUri ();
932
+ auto storePathS = srcStore.printStorePath (storePath);
933
+ Activity act (*logger, lvlInfo, actCopyPath,
934
+ makeCopyPathMessage (srcUri, dstUri, storePathS),
935
+ {storePathS, srcUri, dstUri});
936
+ PushActivity pact (act.id );
937
+
938
+ auto info = srcStore.queryPathInfo (storePath);
939
+ info->write (sink, srcStore, 16 );
940
+ srcStore.narFromPath (storePath, sink);
906
941
}
907
- return pathsMap;
908
- }
942
+ });
909
943
910
- Activity act (*logger, lvlInfo, actCopyPaths, fmt ( " copying %d paths " , missing. size ()) );
944
+ dstStore. addMultipleToStore (*source, repair, checkSigs );
911
945
946
+ #if 0
912
947
std::atomic<size_t> nrDone{0};
913
948
std::atomic<size_t> nrFailed{0};
914
949
std::atomic<uint64_t> bytesExpected{0};
@@ -986,6 +1021,8 @@ std::map<StorePath, StorePath> copyPaths(
986
1021
nrDone++;
987
1022
showProgress();
988
1023
});
1024
+ #endif
1025
+
989
1026
return pathsMap;
990
1027
}
991
1028
0 commit comments