Skip to content

Commit b770cd2

Browse files
authored
Add stat RPC (#614)
Add `Stat` RPC to vminitd. `Stat` RPC is used to stat file system objects in the VM. It accepts the path to the object (resolved against VM root) and returns the stat result.
1 parent 59f599e commit b770cd2

8 files changed

Lines changed: 826 additions & 0 deletions

File tree

Sources/Containerization/SandboxContext/SandboxContext.grpc.swift

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContext: Sendable {
166166
type: .serverStreaming
167167
)
168168
}
169+
/// Namespace for "Stat" metadata.
170+
public enum Stat: Sendable {
171+
/// Request type for "Stat".
172+
public typealias Input = Com_Apple_Containerization_Sandbox_V3_StatRequest
173+
/// Response type for "Stat".
174+
public typealias Output = Com_Apple_Containerization_Sandbox_V3_StatResponse
175+
/// Descriptor for "Stat".
176+
public static let descriptor = GRPCCore.MethodDescriptor(
177+
service: GRPCCore.ServiceDescriptor(fullyQualifiedService: "com.apple.containerization.sandbox.v3.SandboxContext"),
178+
method: "Stat",
179+
type: .unary
180+
)
181+
}
169182
/// Namespace for "CreateProcess" metadata.
170183
public enum CreateProcess: Sendable {
171184
/// Request type for "CreateProcess".
@@ -412,6 +425,7 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContext: Sendable {
412425
SetupEmulator.descriptor,
413426
WriteFile.descriptor,
414427
Copy.descriptor,
428+
Stat.descriptor,
415429
CreateProcess.descriptor,
416430
DeleteProcess.descriptor,
417431
StartProcess.descriptor,
@@ -641,6 +655,24 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext {
641655
context: GRPCCore.ServerContext
642656
) async throws -> GRPCCore.StreamingServerResponse<Com_Apple_Containerization_Sandbox_V3_CopyResponse>
643657

658+
/// Handle the "Stat" method.
659+
///
660+
/// > Source IDL Documentation:
661+
/// >
662+
/// > Stat a path in the guest filesystem.
663+
///
664+
/// - Parameters:
665+
/// - request: A streaming request of `Com_Apple_Containerization_Sandbox_V3_StatRequest` messages.
666+
/// - context: Context providing information about the RPC.
667+
/// - Throws: Any error which occurred during the processing of the request. Thrown errors
668+
/// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
669+
/// to an internal error.
670+
/// - Returns: A streaming response of `Com_Apple_Containerization_Sandbox_V3_StatResponse` messages.
671+
func stat(
672+
request: GRPCCore.StreamingServerRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
673+
context: GRPCCore.ServerContext
674+
) async throws -> GRPCCore.StreamingServerResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>
675+
644676
/// Handle the "CreateProcess" method.
645677
///
646678
/// > Source IDL Documentation:
@@ -1161,6 +1193,24 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext {
11611193
context: GRPCCore.ServerContext
11621194
) async throws -> GRPCCore.StreamingServerResponse<Com_Apple_Containerization_Sandbox_V3_CopyResponse>
11631195

1196+
/// Handle the "Stat" method.
1197+
///
1198+
/// > Source IDL Documentation:
1199+
/// >
1200+
/// > Stat a path in the guest filesystem.
1201+
///
1202+
/// - Parameters:
1203+
/// - request: A request containing a single `Com_Apple_Containerization_Sandbox_V3_StatRequest` message.
1204+
/// - context: Context providing information about the RPC.
1205+
/// - Throws: Any error which occurred during the processing of the request. Thrown errors
1206+
/// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
1207+
/// to an internal error.
1208+
/// - Returns: A response containing a single `Com_Apple_Containerization_Sandbox_V3_StatResponse` message.
1209+
func stat(
1210+
request: GRPCCore.ServerRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
1211+
context: GRPCCore.ServerContext
1212+
) async throws -> GRPCCore.ServerResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>
1213+
11641214
/// Handle the "CreateProcess" method.
11651215
///
11661216
/// > Source IDL Documentation:
@@ -1680,6 +1730,24 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext {
16801730
context: GRPCCore.ServerContext
16811731
) async throws
16821732

1733+
/// Handle the "Stat" method.
1734+
///
1735+
/// > Source IDL Documentation:
1736+
/// >
1737+
/// > Stat a path in the guest filesystem.
1738+
///
1739+
/// - Parameters:
1740+
/// - request: A `Com_Apple_Containerization_Sandbox_V3_StatRequest` message.
1741+
/// - context: Context providing information about the RPC.
1742+
/// - Throws: Any error which occurred during the processing of the request. Thrown errors
1743+
/// of type `RPCError` are mapped to appropriate statuses. All other errors are converted
1744+
/// to an internal error.
1745+
/// - Returns: A `Com_Apple_Containerization_Sandbox_V3_StatResponse` to respond with.
1746+
func stat(
1747+
request: Com_Apple_Containerization_Sandbox_V3_StatRequest,
1748+
context: GRPCCore.ServerContext
1749+
) async throws -> Com_Apple_Containerization_Sandbox_V3_StatResponse
1750+
16831751
/// Handle the "CreateProcess" method.
16841752
///
16851753
/// > Source IDL Documentation:
@@ -2121,6 +2189,17 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext.StreamingServiceP
21212189
)
21222190
}
21232191
)
2192+
router.registerHandler(
2193+
forMethod: Com_Apple_Containerization_Sandbox_V3_SandboxContext.Method.Stat.descriptor,
2194+
deserializer: GRPCProtobuf.ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_StatRequest>(),
2195+
serializer: GRPCProtobuf.ProtobufSerializer<Com_Apple_Containerization_Sandbox_V3_StatResponse>(),
2196+
handler: { request, context in
2197+
try await self.stat(
2198+
request: request,
2199+
context: context
2200+
)
2201+
}
2202+
)
21242203
router.registerHandler(
21252204
forMethod: Com_Apple_Containerization_Sandbox_V3_SandboxContext.Method.CreateProcess.descriptor,
21262205
deserializer: GRPCProtobuf.ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_CreateProcessRequest>(),
@@ -2435,6 +2514,17 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext.ServiceProtocol {
24352514
return response
24362515
}
24372516

2517+
public func stat(
2518+
request: GRPCCore.StreamingServerRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
2519+
context: GRPCCore.ServerContext
2520+
) async throws -> GRPCCore.StreamingServerResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse> {
2521+
let response = try await self.stat(
2522+
request: GRPCCore.ServerRequest(stream: request),
2523+
context: context
2524+
)
2525+
return GRPCCore.StreamingServerResponse(single: response)
2526+
}
2527+
24382528
public func createProcess(
24392529
request: GRPCCore.StreamingServerRequest<Com_Apple_Containerization_Sandbox_V3_CreateProcessRequest>,
24402530
context: GRPCCore.ServerContext
@@ -2771,6 +2861,19 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext.SimpleServiceProt
27712861
)
27722862
}
27732863

2864+
public func stat(
2865+
request: GRPCCore.ServerRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
2866+
context: GRPCCore.ServerContext
2867+
) async throws -> GRPCCore.ServerResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse> {
2868+
return GRPCCore.ServerResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>(
2869+
message: try await self.stat(
2870+
request: request.message,
2871+
context: context
2872+
),
2873+
metadata: [:]
2874+
)
2875+
}
2876+
27742877
public func createProcess(
27752878
request: GRPCCore.ServerRequest<Com_Apple_Containerization_Sandbox_V3_CreateProcessRequest>,
27762879
context: GRPCCore.ServerContext
@@ -3251,6 +3354,29 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext {
32513354
onResponse handleResponse: @Sendable @escaping (GRPCCore.StreamingClientResponse<Com_Apple_Containerization_Sandbox_V3_CopyResponse>) async throws -> Result
32523355
) async throws -> Result where Result: Sendable
32533356

3357+
/// Call the "Stat" method.
3358+
///
3359+
/// > Source IDL Documentation:
3360+
/// >
3361+
/// > Stat a path in the guest filesystem.
3362+
///
3363+
/// - Parameters:
3364+
/// - request: A request containing a single `Com_Apple_Containerization_Sandbox_V3_StatRequest` message.
3365+
/// - serializer: A serializer for `Com_Apple_Containerization_Sandbox_V3_StatRequest` messages.
3366+
/// - deserializer: A deserializer for `Com_Apple_Containerization_Sandbox_V3_StatResponse` messages.
3367+
/// - options: Options to apply to this RPC.
3368+
/// - handleResponse: A closure which handles the response, the result of which is
3369+
/// returned to the caller. Returning from the closure will cancel the RPC if it
3370+
/// hasn't already finished.
3371+
/// - Returns: The result of `handleResponse`.
3372+
func stat<Result>(
3373+
request: GRPCCore.ClientRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
3374+
serializer: some GRPCCore.MessageSerializer<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
3375+
deserializer: some GRPCCore.MessageDeserializer<Com_Apple_Containerization_Sandbox_V3_StatResponse>,
3376+
options: GRPCCore.CallOptions,
3377+
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>) async throws -> Result
3378+
) async throws -> Result where Result: Sendable
3379+
32543380
/// Call the "CreateProcess" method.
32553381
///
32563382
/// > Source IDL Documentation:
@@ -4027,6 +4153,40 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext {
40274153
)
40284154
}
40294155

4156+
/// Call the "Stat" method.
4157+
///
4158+
/// > Source IDL Documentation:
4159+
/// >
4160+
/// > Stat a path in the guest filesystem.
4161+
///
4162+
/// - Parameters:
4163+
/// - request: A request containing a single `Com_Apple_Containerization_Sandbox_V3_StatRequest` message.
4164+
/// - serializer: A serializer for `Com_Apple_Containerization_Sandbox_V3_StatRequest` messages.
4165+
/// - deserializer: A deserializer for `Com_Apple_Containerization_Sandbox_V3_StatResponse` messages.
4166+
/// - options: Options to apply to this RPC.
4167+
/// - handleResponse: A closure which handles the response, the result of which is
4168+
/// returned to the caller. Returning from the closure will cancel the RPC if it
4169+
/// hasn't already finished.
4170+
/// - Returns: The result of `handleResponse`.
4171+
public func stat<Result>(
4172+
request: GRPCCore.ClientRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
4173+
serializer: some GRPCCore.MessageSerializer<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
4174+
deserializer: some GRPCCore.MessageDeserializer<Com_Apple_Containerization_Sandbox_V3_StatResponse>,
4175+
options: GRPCCore.CallOptions = .defaults,
4176+
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>) async throws -> Result = { response in
4177+
try response.message
4178+
}
4179+
) async throws -> Result where Result: Sendable {
4180+
try await self.client.unary(
4181+
request: request,
4182+
descriptor: Com_Apple_Containerization_Sandbox_V3_SandboxContext.Method.Stat.descriptor,
4183+
serializer: serializer,
4184+
deserializer: deserializer,
4185+
options: options,
4186+
onResponse: handleResponse
4187+
)
4188+
}
4189+
40304190
/// Call the "CreateProcess" method.
40314191
///
40324192
/// > Source IDL Documentation:
@@ -4935,6 +5095,35 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext.ClientProtocol {
49355095
)
49365096
}
49375097

5098+
/// Call the "Stat" method.
5099+
///
5100+
/// > Source IDL Documentation:
5101+
/// >
5102+
/// > Stat a path in the guest filesystem.
5103+
///
5104+
/// - Parameters:
5105+
/// - request: A request containing a single `Com_Apple_Containerization_Sandbox_V3_StatRequest` message.
5106+
/// - options: Options to apply to this RPC.
5107+
/// - handleResponse: A closure which handles the response, the result of which is
5108+
/// returned to the caller. Returning from the closure will cancel the RPC if it
5109+
/// hasn't already finished.
5110+
/// - Returns: The result of `handleResponse`.
5111+
public func stat<Result>(
5112+
request: GRPCCore.ClientRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>,
5113+
options: GRPCCore.CallOptions = .defaults,
5114+
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>) async throws -> Result = { response in
5115+
try response.message
5116+
}
5117+
) async throws -> Result where Result: Sendable {
5118+
try await self.stat(
5119+
request: request,
5120+
serializer: GRPCProtobuf.ProtobufSerializer<Com_Apple_Containerization_Sandbox_V3_StatRequest>(),
5121+
deserializer: GRPCProtobuf.ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_StatResponse>(),
5122+
options: options,
5123+
onResponse: handleResponse
5124+
)
5125+
}
5126+
49385127
/// Call the "CreateProcess" method.
49395128
///
49405129
/// > Source IDL Documentation:
@@ -5792,6 +5981,39 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContext.ClientProtocol {
57925981
)
57935982
}
57945983

5984+
/// Call the "Stat" method.
5985+
///
5986+
/// > Source IDL Documentation:
5987+
/// >
5988+
/// > Stat a path in the guest filesystem.
5989+
///
5990+
/// - Parameters:
5991+
/// - message: request message to send.
5992+
/// - metadata: Additional metadata to send, defaults to empty.
5993+
/// - options: Options to apply to this RPC, defaults to `.defaults`.
5994+
/// - handleResponse: A closure which handles the response, the result of which is
5995+
/// returned to the caller. Returning from the closure will cancel the RPC if it
5996+
/// hasn't already finished.
5997+
/// - Returns: The result of `handleResponse`.
5998+
public func stat<Result>(
5999+
_ message: Com_Apple_Containerization_Sandbox_V3_StatRequest,
6000+
metadata: GRPCCore.Metadata = [:],
6001+
options: GRPCCore.CallOptions = .defaults,
6002+
onResponse handleResponse: @Sendable @escaping (GRPCCore.ClientResponse<Com_Apple_Containerization_Sandbox_V3_StatResponse>) async throws -> Result = { response in
6003+
try response.message
6004+
}
6005+
) async throws -> Result where Result: Sendable {
6006+
let request = GRPCCore.ClientRequest<Com_Apple_Containerization_Sandbox_V3_StatRequest>(
6007+
message: message,
6008+
metadata: metadata
6009+
)
6010+
return try await self.stat(
6011+
request: request,
6012+
options: options,
6013+
onResponse: handleResponse
6014+
)
6015+
}
6016+
57956017
/// Call the "CreateProcess" method.
57966018
///
57976019
/// > Source IDL Documentation:

0 commit comments

Comments
 (0)