mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-24 23:06:16 +02:00
LocalStore::addToStore(srcPath): Handle the flat case
This helps nix-prefetch-url when using a local store.
This commit is contained in:
parent
2dd8443e30
commit
a2c27022e9
1 changed files with 13 additions and 7 deletions
|
@ -1097,16 +1097,13 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
|
||||||
{
|
{
|
||||||
Path srcPath(absPath(_srcPath));
|
Path srcPath(absPath(_srcPath));
|
||||||
|
|
||||||
if (method != FileIngestionMethod::Recursive)
|
|
||||||
return addToStoreFromDump(readFile(srcPath), name, method, hashAlgo, repair);
|
|
||||||
|
|
||||||
/* For computing the NAR hash. */
|
/* For computing the NAR hash. */
|
||||||
auto sha256Sink = std::make_unique<HashSink>(htSHA256);
|
auto sha256Sink = std::make_unique<HashSink>(htSHA256);
|
||||||
|
|
||||||
/* For computing the store path. In recursive SHA-256 mode, this
|
/* 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. */
|
is the same as the NAR hash, so no need to do it again. */
|
||||||
std::unique_ptr<HashSink> hashSink =
|
std::unique_ptr<HashSink> hashSink =
|
||||||
hashAlgo == htSHA256
|
method == FileIngestionMethod::Recursive && hashAlgo == htSHA256
|
||||||
? nullptr
|
? nullptr
|
||||||
: std::make_unique<HashSink>(hashAlgo);
|
: std::make_unique<HashSink>(hashAlgo);
|
||||||
|
|
||||||
|
@ -1139,7 +1136,10 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
|
||||||
if (!inMemory) sink(buf, len);
|
if (!inMemory) sink(buf, len);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (method == FileIngestionMethod::Recursive)
|
||||||
dumpPath(srcPath, sink2, filter);
|
dumpPath(srcPath, sink2, filter);
|
||||||
|
else
|
||||||
|
readFile(srcPath, sink2);
|
||||||
});
|
});
|
||||||
|
|
||||||
std::unique_ptr<AutoDelete> delTempDir;
|
std::unique_ptr<AutoDelete> delTempDir;
|
||||||
|
@ -1155,7 +1155,10 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
|
||||||
delTempDir = std::make_unique<AutoDelete>(tempDir);
|
delTempDir = std::make_unique<AutoDelete>(tempDir);
|
||||||
tempPath = tempDir + "/x";
|
tempPath = tempDir + "/x";
|
||||||
|
|
||||||
|
if (method == FileIngestionMethod::Recursive)
|
||||||
restorePath(tempPath, *source);
|
restorePath(tempPath, *source);
|
||||||
|
else
|
||||||
|
writeFile(tempPath, *source);
|
||||||
|
|
||||||
} catch (EndOfFile &) {
|
} catch (EndOfFile &) {
|
||||||
if (!inMemory) throw;
|
if (!inMemory) throw;
|
||||||
|
@ -1188,7 +1191,10 @@ StorePath LocalStore::addToStore(const string & name, const Path & _srcPath,
|
||||||
if (inMemory) {
|
if (inMemory) {
|
||||||
/* Restore from the NAR in memory. */
|
/* Restore from the NAR in memory. */
|
||||||
StringSource source(nar);
|
StringSource source(nar);
|
||||||
|
if (method == FileIngestionMethod::Recursive)
|
||||||
restorePath(realPath, source);
|
restorePath(realPath, source);
|
||||||
|
else
|
||||||
|
writeFile(realPath, source);
|
||||||
} else {
|
} else {
|
||||||
/* Move the temporary path we restored above. */
|
/* Move the temporary path we restored above. */
|
||||||
if (rename(tempPath.c_str(), realPath.c_str()))
|
if (rename(tempPath.c_str(), realPath.c_str()))
|
||||||
|
|
Loading…
Reference in a new issue