diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c50fbdcdd..2dd428d7e 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -2087,16 +2087,13 @@ StorePath EvalState::copyPathToStore(PathSet & context, const SourcePath & path) auto dstPath = i != srcToStore.end() ? i->second : [&]() { - #if 0 - auto p = settings.readOnlyMode - ? store->computeStorePathForPath(path2.baseName(), canonPath(path)).first - : store->addToStore(path2.baseName(), canonPath(path), FileIngestionMethod::Recursive, htSHA256, defaultPathFilter, repair); - #endif auto source = sinkToSource([&](Sink & sink) { path.dumpPath(sink); }); - // FIXME: readOnlyMode - auto dstPath = store->addToStoreFromDump(*source, path.baseName(), FileIngestionMethod::Recursive, htSHA256, repair); + auto dstPath = + settings.readOnlyMode + ? store->computeStorePathFromDump(*source, path.baseName()).first + : store->addToStoreFromDump(*source, path.baseName(), FileIngestionMethod::Recursive, htSHA256, repair); allowPath(dstPath); srcToStore.insert_or_assign(path, dstPath); printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, store->printStorePath(dstPath)); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 8861274a2..b7b320faf 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -230,6 +230,19 @@ std::pair Store::computeStorePathForPath(std::string_view name, } +std::pair Store::computeStorePathFromDump( + Source & dump, + std::string_view name, + FileIngestionMethod method, + HashType hashAlgo) const +{ + HashSink sink(hashAlgo); + dump.drainInto(sink); + auto hash = sink.finish().first; + return {makeFixedOutputPath(method, hash, name), hash}; +} + + StorePath Store::computeStorePathForText( std::string_view name, std::string_view s, diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0c8a4db56..d9681c765 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -219,10 +219,17 @@ public: /* This is the preparatory part of addToStore(); it computes the store path to which srcPath is to be copied. Returns the store path and the cryptographic hash of the contents of srcPath. */ + // FIXME: remove std::pair computeStorePathForPath(std::string_view name, const Path & srcPath, FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter) const; + std::pair computeStorePathFromDump( + Source & dump, + std::string_view name, + FileIngestionMethod method = FileIngestionMethod::Recursive, + HashType hashAlgo = htSHA256) const; + /* Preparatory part of addTextToStore(). !!! Computation of the path should take the references given to