Merge "libstore: parse the buildMode instead of unchecked cast" into main

This commit is contained in:
jade 2024-05-25 17:42:09 +00:00 committed by Gerrit Code Review
commit dd53bce476
3 changed files with 14 additions and 3 deletions

View file

@ -527,7 +527,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn);
BuildMode mode = bmNormal; BuildMode mode = bmNormal;
if (GET_PROTOCOL_MINOR(clientVersion) >= 15) { if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
mode = (BuildMode) readInt(from); mode = buildModeFromInteger(readInt(from));
/* Repairing is not atomic, so disallowed for "untrusted" /* Repairing is not atomic, so disallowed for "untrusted"
clients. clients.
@ -551,7 +551,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case WorkerProto::Op::BuildPathsWithResults: { case WorkerProto::Op::BuildPathsWithResults: {
auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn);
BuildMode mode = bmNormal; BuildMode mode = bmNormal;
mode = (BuildMode) readInt(from); mode = buildModeFromInteger(readInt(from));
/* Repairing is not atomic, so disallowed for "untrusted" /* Repairing is not atomic, so disallowed for "untrusted"
clients. clients.
@ -582,7 +582,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
* correctly. * correctly.
*/ */
readDerivation(from, *store, drv, Derivation::nameFromPath(drvPath)); readDerivation(from, *store, drv, Derivation::nameFromPath(drvPath));
BuildMode buildMode = (BuildMode) readInt(from); BuildMode buildMode = buildModeFromInteger(readInt(from));
logger->startWork(); logger->startWork();
auto drvType = drv.type(); auto drvType = drv.type();

View file

@ -22,6 +22,14 @@ using json = nlohmann::json;
namespace nix { namespace nix {
BuildMode buildModeFromInteger(int raw) {
switch (raw) {
case bmNormal: return bmNormal;
case bmRepair: return bmRepair;
case bmCheck: return bmCheck;
default: throw Error("Invalid BuildMode");
}
}
bool Store::isInStore(PathView path) const bool Store::isInStore(PathView path) const
{ {

View file

@ -90,6 +90,9 @@ const uint32_t exportMagic = 0x4558494e;
enum BuildMode { bmNormal, bmRepair, bmCheck }; enum BuildMode { bmNormal, bmRepair, bmCheck };
/** Checks that a build mode is a valid one, then returns it */
BuildMode buildModeFromInteger(int);
enum TrustedFlag : bool { NotTrusted = false, Trusted = true }; enum TrustedFlag : bool { NotTrusted = false, Trusted = true };
struct BuildResult; struct BuildResult;