Skip to content

Commit

Permalink
Revert "LocalStore::addToStore(srcPath): Handle the flat case"
Browse files Browse the repository at this point in the history
This reverts commit a2c2702. See
addToStoreSlow(), we don't need to handle this case efficiently
anymore. In fact, we can almost remove the method/hashAlgo arguments
since the non-recursive and/or non-SHA256 are almost not used anymore.
  • Loading branch information
edolstra committed Jul 15, 2020
1 parent 926c3a6 commit cff2157
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1097,13 +1097,16 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
{
Path srcPath(absPath(_srcPath));

if (method != FileIngestionMethod::Recursive)
return addToStoreFromDump(readFile(srcPath), name, method, hashAlgo, repair);

/* For computing the NAR hash. */
auto sha256Sink = std::make_unique<HashSink>(htSHA256);

/* For computing the store path. In recursive SHA-256 mode, this
is the same as the NAR hash, so no need to do it again. */
std::unique_ptr<HashSink> hashSink =
method == FileIngestionMethod::Recursive && hashAlgo == htSHA256
hashAlgo == htSHA256
? nullptr
: std::make_unique<HashSink>(hashAlgo);

Expand Down Expand Up @@ -1136,10 +1139,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
if (!inMemory) sink(buf, len);
});

if (method == FileIngestionMethod::Recursive)
dumpPath(srcPath, sink2, filter);
else
readFile(srcPath, sink2);
dumpPath(srcPath, sink2, filter);
});

std::unique_ptr<AutoDelete> delTempDir;
Expand All @@ -1155,10 +1155,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
delTempDir = std::make_unique<AutoDelete>(tempDir);
tempPath = tempDir + "/x";

if (method == FileIngestionMethod::Recursive)
restorePath(tempPath, *source);
else
writeFile(tempPath, *source);
restorePath(tempPath, *source);

} catch (EndOfFile &) {
if (!inMemory) throw;
Expand Down Expand Up @@ -1191,10 +1188,7 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
if (inMemory) {
/* Restore from the NAR in memory. */
StringSource source(nar);
if (method == FileIngestionMethod::Recursive)
restorePath(realPath, source);
else
writeFile(realPath, source);
restorePath(realPath, source);
} else {
/* Move the temporary path we restored above. */
if (rename(tempPath.c_str(), realPath.c_str()))
Expand Down

0 comments on commit cff2157

Please sign in to comment.