diff options
author | jade <lix@jade.fyi> | 2024-05-25 17:42:09 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@lix-systems> | 2024-05-25 17:42:09 +0000 |
commit | dd53bce476805b41f2e9858e64e38574a88db77f (patch) | |
tree | 68799abbb03929a4f0c2d81e34a5e0b3b5c9fc51 /src | |
parent | ddfe379a6b93c678a9a0845e5c5a85f7e77b1b7d (diff) | |
parent | 2a7a824d83dc5fb33326b8b89625685f283a743b (diff) |
Merge "libstore: parse the buildMode instead of unchecked cast" into main
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/daemon.cc | 6 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 8 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 242b4ddc6..420fc8bfe 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -527,7 +527,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store, auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); BuildMode mode = bmNormal; if (GET_PROTOCOL_MINOR(clientVersion) >= 15) { - mode = (BuildMode) readInt(from); + mode = buildModeFromInteger(readInt(from)); /* Repairing is not atomic, so disallowed for "untrusted" clients. @@ -551,7 +551,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store, case WorkerProto::Op::BuildPathsWithResults: { auto drvs = WorkerProto::Serialise<DerivedPaths>::read(*store, rconn); BuildMode mode = bmNormal; - mode = (BuildMode) readInt(from); + mode = buildModeFromInteger(readInt(from)); /* Repairing is not atomic, so disallowed for "untrusted" clients. @@ -582,7 +582,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store, * correctly. */ readDerivation(from, *store, drv, Derivation::nameFromPath(drvPath)); - BuildMode buildMode = (BuildMode) readInt(from); + BuildMode buildMode = buildModeFromInteger(readInt(from)); logger->startWork(); auto drvType = drv.type(); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 509b0fa68..ed3566f5e 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -22,6 +22,14 @@ using json = nlohmann::json; 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 { diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 47e644fed..745fce594 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -90,6 +90,9 @@ const uint32_t exportMagic = 0x4558494e; 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 }; struct BuildResult; |