Skip to content

Commit 3d94d4c

Browse files
committed
client side implementation of filesystemOperation
1 parent 6616288 commit 3d94d4c

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Sources/Containerization/VirtualMachineAgent.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public struct WriteFileFlags {
2525
public var create = false
2626
}
2727

28+
public enum FilesystemOperation {
29+
case freeze
30+
case thaw
31+
}
32+
2833
/// A protocol for the agent running inside a virtual machine. If an operation isn't
2934
/// supported the implementation MUST return a ContainerizationError with a code of
3035
/// `.unsupported`.
@@ -34,6 +39,8 @@ public protocol VirtualMachineAgent: Sendable {
3439
func standardSetup() async throws
3540
/// Close any resources held by the agent.
3641
func close() async throws
42+
// Perform a filesystem operation on the given path.
43+
func filesystemOperation(operation: FilesystemOperation, path: String) async throws
3744

3845
// POSIX-y
3946
func getenv(key: String) async throws -> String

Sources/Containerization/Vminitd.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ extension Vminitd: VirtualMachineAgent {
202202
})
203203
}
204204

205+
/// Perform a filesystem operation on a path inside the sandbox's environment.
206+
public func filesystemOperation(operation: FilesystemOperation, path: String) async throws {
207+
_ = try await client.filesystemOperation(
208+
.with {
209+
$0.operation = operation.toProtoOperation()
210+
$0.path = path
211+
})
212+
}
213+
205214
public func createProcess(
206215
id: String,
207216
containerID: String?,
@@ -586,3 +595,15 @@ extension StatCategory {
586595
return categories
587596
}
588597
}
598+
599+
extension FilesystemOperation {
600+
/// Convert FilesystemOperation to proto oneof value.
601+
func toProtoOperation() -> Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest.OneOf_Operation {
602+
switch self {
603+
case .freeze:
604+
return .freeze(.init())
605+
case .thaw:
606+
return .thaw(.init())
607+
}
608+
}
609+
}

0 commit comments

Comments
 (0)