libstore: split Store::addToStore
same as before, only for a different method. Change-Id: Id7238b26a25c21fe09df7147b16a39cc5371d8c0
This commit is contained in:
@@ -183,7 +183,9 @@ static void opAdd(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
|
||||
for (auto & i : opArgs) {
|
||||
cout << fmt(
|
||||
"%s\n",
|
||||
store->printStorePath(aio.blockOn(store->addToStore(std::string(baseNameOf(i)), i)))
|
||||
store->printStorePath(
|
||||
aio.blockOn(store->addToStoreRecursive(std::string(baseNameOf(i)), i))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,14 @@ try {
|
||||
co_return store.computeStorePathForPathFlat(name, physicalPath);
|
||||
}
|
||||
} else {
|
||||
co_return TRY_AWAIT(
|
||||
store.addToStore(name, physicalPath, method, HashType::SHA256, filter2, repair)
|
||||
);
|
||||
switch (method) {
|
||||
case FileIngestionMethod::Recursive:
|
||||
co_return TRY_AWAIT(
|
||||
store.addToStoreRecursive(name, physicalPath, HashType::SHA256, filter2, repair)
|
||||
);
|
||||
case FileIngestionMethod::Flat:
|
||||
co_return TRY_AWAIT(store.addToStoreFlat(name, physicalPath, HashType::SHA256, repair));
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
|
||||
@@ -242,8 +242,8 @@ try {
|
||||
return files.count(file);
|
||||
};
|
||||
|
||||
auto storePath = TRY_AWAIT(store->addToStore(
|
||||
input.getName(), actualPath, FileIngestionMethod::Recursive, HashType::SHA256, filter
|
||||
auto storePath = TRY_AWAIT(store->addToStoreRecursive(
|
||||
input.getName(), actualPath, HashType::SHA256, filter
|
||||
));
|
||||
|
||||
// FIXME: maybe we should use the timestamp of the last
|
||||
@@ -770,9 +770,8 @@ struct GitInputScheme : InputScheme
|
||||
unpackTarfile(*proc.getStdout(), tmpDir);
|
||||
}
|
||||
|
||||
auto storePath = TRY_AWAIT(store->addToStore(
|
||||
name, tmpDir, FileIngestionMethod::Recursive, HashType::SHA256, filter
|
||||
));
|
||||
auto storePath =
|
||||
TRY_AWAIT(store->addToStoreRecursive(name, tmpDir, HashType::SHA256, filter));
|
||||
|
||||
auto lastModified = std::stoull(runProgram("git", true, { "-C", repoDir, "--git-dir", gitDir, "log", "-1", "--format=%ct", "--no-show-signature", input.getRev()->gitRev() }));
|
||||
|
||||
|
||||
@@ -202,12 +202,8 @@ struct MercurialInputScheme : InputScheme
|
||||
return files.count(file);
|
||||
};
|
||||
|
||||
auto storePath = TRY_AWAIT(store->addToStore(
|
||||
input.getName(),
|
||||
actualPath,
|
||||
FileIngestionMethod::Recursive,
|
||||
HashType::SHA256,
|
||||
filter
|
||||
auto storePath = TRY_AWAIT(store->addToStoreRecursive(
|
||||
input.getName(), actualPath, HashType::SHA256, filter
|
||||
));
|
||||
|
||||
co_return {std::move(storePath), input};
|
||||
@@ -319,7 +315,7 @@ struct MercurialInputScheme : InputScheme
|
||||
|
||||
deletePath(tmpDir + "/.hg_archival.txt");
|
||||
|
||||
auto storePath = TRY_AWAIT(store->addToStore(name, tmpDir));
|
||||
auto storePath = TRY_AWAIT(store->addToStoreRecursive(name, tmpDir));
|
||||
|
||||
Attrs infoAttrs({
|
||||
{"rev", input.getRev()->gitRev()},
|
||||
|
||||
@@ -161,14 +161,9 @@ try {
|
||||
throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url);
|
||||
auto topDir = tmpDir + "/" + members.begin()->name;
|
||||
lastModified = lstat(topDir).st_mtime;
|
||||
unpackedStorePath = TRY_AWAIT(store->addToStore(
|
||||
name,
|
||||
topDir,
|
||||
FileIngestionMethod::Recursive,
|
||||
HashType::SHA256,
|
||||
defaultPathFilter,
|
||||
NoRepair
|
||||
));
|
||||
unpackedStorePath = TRY_AWAIT(
|
||||
store->addToStoreRecursive(name, topDir, HashType::SHA256, defaultPathFilter, NoRepair)
|
||||
);
|
||||
}
|
||||
|
||||
Attrs infoAttrs({
|
||||
|
||||
@@ -376,10 +376,31 @@ std::shared_ptr<const ValidPathInfo> BinaryCacheStore::queryPathInfoUncached(con
|
||||
return std::make_shared<NarInfo>(*this, *data, narInfoFile);
|
||||
}
|
||||
|
||||
kj::Promise<Result<StorePath>> BinaryCacheStore::addToStore(
|
||||
static ValidPathInfo makeAddToStoreInfo(
|
||||
HashResult nar, Store & store, FileIngestionMethod method, std::string_view name, Hash h
|
||||
)
|
||||
{
|
||||
ValidPathInfo info{
|
||||
store,
|
||||
name,
|
||||
FixedOutputInfo {
|
||||
.method = method,
|
||||
.hash = h,
|
||||
.references = {
|
||||
.others = {},
|
||||
// caller is not capable of creating a self-reference, because this is content-addressed without modulus
|
||||
.self = false,
|
||||
},
|
||||
},
|
||||
nar.first,
|
||||
};
|
||||
info.narSize = nar.second;
|
||||
return info;
|
||||
}
|
||||
|
||||
kj::Promise<Result<StorePath>> BinaryCacheStore::addToStoreRecursive(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
FileIngestionMethod method,
|
||||
HashType hashAlgo,
|
||||
PathFilter & filter,
|
||||
RepairFlag repair)
|
||||
@@ -389,31 +410,34 @@ try {
|
||||
implementation of this method in terms of addToStoreFromDump. */
|
||||
|
||||
HashSink sink { hashAlgo };
|
||||
if (method == FileIngestionMethod::Recursive) {
|
||||
sink << dumpPath(srcPath, filter);
|
||||
} else {
|
||||
sink << readFileSource(srcPath);
|
||||
}
|
||||
sink << dumpPath(srcPath, filter);
|
||||
auto h = sink.finish().first;
|
||||
|
||||
auto source = GeneratorSource{dumpPath(srcPath, filter)};
|
||||
co_return TRY_AWAIT(addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) {
|
||||
ValidPathInfo info {
|
||||
*this,
|
||||
name,
|
||||
FixedOutputInfo {
|
||||
.method = method,
|
||||
.hash = h,
|
||||
.references = {
|
||||
.others = {},
|
||||
// caller is not capable of creating a self-reference, because this is content-addressed without modulus
|
||||
.self = false,
|
||||
},
|
||||
},
|
||||
nar.first,
|
||||
};
|
||||
info.narSize = nar.second;
|
||||
return info;
|
||||
return makeAddToStoreInfo(nar, *this, FileIngestionMethod::Recursive, name, h);
|
||||
}))->path;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
kj::Promise<Result<StorePath>> BinaryCacheStore::addToStoreFlat(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
HashType hashAlgo,
|
||||
RepairFlag repair)
|
||||
try {
|
||||
/* FIXME: Make BinaryCacheStore::addToStoreCommon support
|
||||
non-recursive+sha256 so we can just use the default
|
||||
implementation of this method in terms of addToStoreFromDump. */
|
||||
|
||||
HashSink sink { hashAlgo };
|
||||
sink << readFileSource(srcPath);
|
||||
auto h = sink.finish().first;
|
||||
|
||||
auto source = GeneratorSource{dumpPath(srcPath)};
|
||||
co_return TRY_AWAIT(addToStoreCommon(source, repair, CheckSigs, [&](HashResult nar) {
|
||||
return makeAddToStoreInfo(nar, *this, FileIngestionMethod::Flat, name, h);
|
||||
}))->path;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
|
||||
@@ -119,13 +119,17 @@ public:
|
||||
kj::Promise<Result<StorePath>> addToStoreFromDump(Source & dump, std::string_view name,
|
||||
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) override;
|
||||
|
||||
kj::Promise<Result<StorePath>> addToStore(
|
||||
kj::Promise<Result<StorePath>> addToStoreRecursive(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
FileIngestionMethod method,
|
||||
HashType hashAlgo,
|
||||
PathFilter & filter,
|
||||
RepairFlag repair) override;
|
||||
kj::Promise<Result<StorePath>> addToStoreFlat(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
HashType hashAlgo,
|
||||
RepairFlag repair) override;
|
||||
|
||||
kj::Promise<Result<StorePath>> addTextToStore(
|
||||
std::string_view name,
|
||||
|
||||
@@ -1081,14 +1081,20 @@ struct RestrictedStore : public virtual IndirectRootStore, public virtual GcStor
|
||||
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
|
||||
{ throw Error("queryPathFromHashPart"); }
|
||||
|
||||
kj::Promise<Result<StorePath>> addToStore(
|
||||
kj::Promise<Result<StorePath>> addToStoreRecursive(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
FileIngestionMethod method,
|
||||
HashType hashAlgo,
|
||||
PathFilter & filter,
|
||||
RepairFlag repair) override
|
||||
try { throw Error("addToStore"); } catch (...) { return {result::current_exception()}; }
|
||||
try { throw Error("addToStoreRecursive"); } catch (...) { return {result::current_exception()}; }
|
||||
|
||||
kj::Promise<Result<StorePath>> addToStoreFlat(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
HashType hashAlgo,
|
||||
RepairFlag repair) override
|
||||
try { throw Error("addToStoreFlat"); } catch (...) { return {result::current_exception()}; }
|
||||
|
||||
kj::Promise<Result<void>> addToStore(const ValidPathInfo & info, Source & narSource,
|
||||
RepairFlag repair = NoRepair, CheckSigsFlag checkSigs = CheckSigs) override
|
||||
|
||||
@@ -262,14 +262,20 @@ struct LegacySSHStore final : public Store
|
||||
std::optional<StorePath> queryPathFromHashPart(const std::string & hashPart) override
|
||||
{ unsupported("queryPathFromHashPart"); }
|
||||
|
||||
kj::Promise<Result<StorePath>> addToStore(
|
||||
kj::Promise<Result<StorePath>> addToStoreRecursive(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
FileIngestionMethod method,
|
||||
HashType hashAlgo,
|
||||
PathFilter & filter,
|
||||
RepairFlag repair) override
|
||||
try { unsupported("addToStore"); } catch (...) { return {result::current_exception()}; }
|
||||
try { throw Error("addToStoreRecursive"); } catch (...) { return {result::current_exception()}; }
|
||||
|
||||
kj::Promise<Result<StorePath>> addToStoreFlat(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
HashType hashAlgo,
|
||||
RepairFlag repair) override
|
||||
try { throw Error("addToStoreFlat"); } catch (...) { return {result::current_exception()}; }
|
||||
|
||||
kj::Promise<Result<StorePath>> addTextToStore(
|
||||
std::string_view name,
|
||||
|
||||
@@ -280,20 +280,33 @@ StorePath Store::computeStorePathForText(
|
||||
}
|
||||
|
||||
|
||||
kj::Promise<Result<StorePath>> Store::addToStore(
|
||||
kj::Promise<Result<StorePath>> Store::addToStoreRecursive(
|
||||
std::string_view name,
|
||||
const Path & _srcPath,
|
||||
FileIngestionMethod method,
|
||||
HashType hashAlgo,
|
||||
PathFilter & filter,
|
||||
RepairFlag repair)
|
||||
try {
|
||||
Path srcPath(absPath(_srcPath));
|
||||
auto source = GeneratorSource{
|
||||
method == FileIngestionMethod::Recursive ? dumpPath(srcPath, filter).decay()
|
||||
: readFileSource(srcPath)
|
||||
};
|
||||
co_return TRY_AWAIT(addToStoreFromDump(source, name, method, hashAlgo, repair, {}));
|
||||
auto source = GeneratorSource{dumpPath(srcPath, filter)};
|
||||
co_return TRY_AWAIT(
|
||||
addToStoreFromDump(source, name, FileIngestionMethod::Recursive, hashAlgo, repair, {})
|
||||
);
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
kj::Promise<Result<StorePath>> Store::addToStoreFlat(
|
||||
std::string_view name,
|
||||
const Path & _srcPath,
|
||||
HashType hashAlgo,
|
||||
RepairFlag repair)
|
||||
try {
|
||||
Path srcPath(absPath(_srcPath));
|
||||
auto source = GeneratorSource{readFileSource(srcPath)};
|
||||
co_return TRY_AWAIT(
|
||||
addToStoreFromDump(source, name, FileIngestionMethod::Flat, hashAlgo, repair, {})
|
||||
);
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
@@ -526,13 +526,17 @@ public:
|
||||
* @param filter This function can be used to exclude files (see
|
||||
* libutil/archive.hh).
|
||||
*/
|
||||
virtual kj::Promise<Result<StorePath>> addToStore(
|
||||
virtual kj::Promise<Result<StorePath>> addToStoreRecursive(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
FileIngestionMethod method = FileIngestionMethod::Recursive,
|
||||
HashType hashAlgo = HashType::SHA256,
|
||||
PathFilter & filter = defaultPathFilter,
|
||||
RepairFlag repair = NoRepair);
|
||||
virtual kj::Promise<Result<StorePath>> addToStoreFlat(
|
||||
std::string_view name,
|
||||
const Path & srcPath,
|
||||
HashType hashAlgo = HashType::SHA256,
|
||||
RepairFlag repair = NoRepair);
|
||||
|
||||
/**
|
||||
* Copy the contents of a path to the store and register the
|
||||
|
||||
@@ -293,8 +293,10 @@ int checkSignature(SV * publicKey_, SV * sig_, char * msg)
|
||||
SV * addToStore(char * srcPath, int recursive, char * algo)
|
||||
PPCODE:
|
||||
try {
|
||||
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
||||
auto path = aio().blockOn(store()->addToStore(std::string(baseNameOf(srcPath)), srcPath, method, parseHashType(algo)));
|
||||
auto hash = parseHashType(algo);
|
||||
auto path = aio().blockOn(recursive
|
||||
? store()->addToStoreRecursive(std::string(baseNameOf(srcPath)), srcPath, hash)
|
||||
: store()->addToStoreFlat(std::string(baseNameOf(srcPath)), srcPath, hash));
|
||||
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(path).c_str(), 0)));
|
||||
} catch (Error & e) {
|
||||
croak("%s", e.what());
|
||||
|
||||
Reference in New Issue
Block a user