mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
Merge pull request #10781 from obsidiansystems/build-mode-parse
Worker proto use proper serialiser for `BuildMode`
This commit is contained in:
commit
17964441d9
@ -531,7 +531,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 = WorkerProto::Serialise<BuildMode>::read(*store, rconn);
|
||||
|
||||
/* Repairing is not atomic, so disallowed for "untrusted"
|
||||
clients.
|
||||
@ -555,7 +555,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 = WorkerProto::Serialise<BuildMode>::read(*store, rconn);
|
||||
|
||||
/* Repairing is not atomic, so disallowed for "untrusted"
|
||||
clients.
|
||||
@ -586,7 +586,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||
* correctly.
|
||||
*/
|
||||
readDerivation(from, *store, drv, Derivation::nameFromPath(drvPath));
|
||||
BuildMode buildMode = (BuildMode) readInt(from);
|
||||
auto buildMode = WorkerProto::Serialise<BuildMode>::read(*store, rconn);
|
||||
logger->startWork();
|
||||
|
||||
auto drvType = drv.type();
|
||||
|
@ -92,7 +92,7 @@ enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true };
|
||||
const uint32_t exportMagic = 0x4558494e;
|
||||
|
||||
|
||||
enum BuildMode { bmNormal, bmRepair, bmCheck };
|
||||
enum BuildMode : uint8_t { bmNormal, bmRepair, bmCheck };
|
||||
enum TrustedFlag : bool { NotTrusted = false, Trusted = true };
|
||||
|
||||
struct BuildResult;
|
||||
|
@ -14,6 +14,34 @@ namespace nix {
|
||||
|
||||
/* protocol-specific definitions */
|
||||
|
||||
BuildMode WorkerProto::Serialise<BuildMode>::read(const StoreDirConfig & store, WorkerProto::ReadConn conn)
|
||||
{
|
||||
auto temp = readNum<uint8_t>(conn.from);
|
||||
switch (temp) {
|
||||
case 0: return bmNormal;
|
||||
case 1: return bmRepair;
|
||||
case 2: return bmCheck;
|
||||
default: throw Error("Invalid build mode");
|
||||
}
|
||||
}
|
||||
|
||||
void WorkerProto::Serialise<BuildMode>::write(const StoreDirConfig & store, WorkerProto::WriteConn conn, const BuildMode & buildMode)
|
||||
{
|
||||
switch (buildMode) {
|
||||
case bmNormal:
|
||||
conn.to << uint8_t{0};
|
||||
break;
|
||||
case bmRepair:
|
||||
conn.to << uint8_t{1};
|
||||
break;
|
||||
case bmCheck:
|
||||
conn.to << uint8_t{2};
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<TrustedFlag> WorkerProto::Serialise<std::optional<TrustedFlag>>::read(const StoreDirConfig & store, WorkerProto::ReadConn conn)
|
||||
{
|
||||
auto temp = readNum<uint8_t>(conn.from);
|
||||
|
@ -35,6 +35,7 @@ struct BuildResult;
|
||||
struct KeyedBuildResult;
|
||||
struct ValidPathInfo;
|
||||
struct UnkeyedValidPathInfo;
|
||||
enum BuildMode : uint8_t;
|
||||
enum TrustedFlag : bool;
|
||||
|
||||
|
||||
@ -215,6 +216,8 @@ DECLARE_WORKER_SERIALISER(ValidPathInfo);
|
||||
template<>
|
||||
DECLARE_WORKER_SERIALISER(UnkeyedValidPathInfo);
|
||||
template<>
|
||||
DECLARE_WORKER_SERIALISER(BuildMode);
|
||||
template<>
|
||||
DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
|
||||
template<>
|
||||
DECLARE_WORKER_SERIALISER(std::optional<std::chrono::microseconds>);
|
||||
|
BIN
tests/unit/libstore/data/worker-protocol/build-mode.bin
Normal file
BIN
tests/unit/libstore/data/worker-protocol/build-mode.bin
Normal file
Binary file not shown.
@ -529,6 +529,17 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||
}),
|
||||
}))
|
||||
|
||||
VERSIONED_CHARACTERIZATION_TEST(
|
||||
WorkerProtoTest,
|
||||
buildMode,
|
||||
"build-mode",
|
||||
defaultVersion,
|
||||
(std::tuple<BuildMode, BuildMode, BuildMode> {
|
||||
bmNormal,
|
||||
bmRepair,
|
||||
bmCheck,
|
||||
}))
|
||||
|
||||
VERSIONED_CHARACTERIZATION_TEST(
|
||||
WorkerProtoTest,
|
||||
optionalTrustedFlag,
|
||||
|
Loading…
Reference in New Issue
Block a user