mirror of
https://github.com/apple/container.git
synced 2026-09-17 05:05:44 +00:00
Agent: Add and implement writeFile (#259)
This change adds in a new rpc that we probably should swap to for the underlying implementation of a couple rpcs we currently have. This new rpc simply writes to an existing or new file some data. This is useful for guest (and container) setup for things like /etc/hosts, /etc/resolv.conf, writing to one-off cgroup files and so on. Currently I've just implemented subtree_control toggling for the root cg in standardSetup with this new change, but in the future I'd like to swap the implementations of our /etc/hosts and /etc/resolv.conf logic with this.
This commit is contained in:
@@ -18,6 +18,12 @@ import ContainerizationError
|
||||
import ContainerizationOCI
|
||||
import Foundation
|
||||
|
||||
public struct WriteFileFlags {
|
||||
public var createParentDirectories = false
|
||||
public var append = false
|
||||
public var create = false
|
||||
}
|
||||
|
||||
/// A protocol for the agent running inside a virtual machine. If an operation isn't
|
||||
/// supported the implementation MUST return a ContainerizationError with a code of
|
||||
/// `.unsupported`.
|
||||
@@ -28,7 +34,7 @@ public protocol VirtualMachineAgent: Sendable {
|
||||
/// Close any resources held by the agent.
|
||||
func close() async throws
|
||||
|
||||
// POSIX
|
||||
// POSIX-y
|
||||
func getenv(key: String) async throws -> String
|
||||
func setenv(key: String, value: String) async throws
|
||||
func mount(_ mount: ContainerizationOCI.Mount) async throws
|
||||
@@ -36,6 +42,7 @@ public protocol VirtualMachineAgent: Sendable {
|
||||
func mkdir(path: String, all: Bool, perms: UInt32) async throws
|
||||
@discardableResult
|
||||
func kill(pid: Int32, signal: Int32) async throws -> Int32
|
||||
func writeFile(path: String, data: Data, flags: WriteFileFlags, mode: UInt32) async throws
|
||||
|
||||
// Process lifecycle
|
||||
func createProcess(
|
||||
@@ -71,4 +78,8 @@ extension VirtualMachineAgent {
|
||||
public func configureHosts(config: Hosts, location: String) async throws {
|
||||
throw ContainerizationError(.unsupported, message: "configureHosts")
|
||||
}
|
||||
|
||||
public func writeFile(path: String, data: Data, flags: WriteFileFlags, mode: UInt32) async throws {
|
||||
throw ContainerizationError(.unsupported, message: "writeFile")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user