Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Sources/Containerization/LinuxContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,57 @@ extension LinuxContainer {
try await relayManager.start(port: port, socket: socket)
try await relayAgent.relaySocket(port: port, configuration: socket)
}

/// Default chunk size for file transfers (1MiB).
public static let defaultCopyChunkSize = 1024 * 1024

/// Copy a file from the host into the container.
public func copyIn(
from source: URL,
to destination: URL,
mode: UInt32 = 0o644,
createParents: Bool = true,
chunkSize: Int = defaultCopyChunkSize,
progress: ProgressHandler? = nil
) async throws {
try await self.state.withLock {
let state = try $0.startedState("copyIn")

let guestPath = URL(filePath: self.root).appending(path: destination.path)
try await state.vm.withAgent { agent in
try await agent.copyIn(
from: source,
to: guestPath,
mode: mode,
createParents: createParents,
chunkSize: chunkSize,
progress: progress
)
}
}
}

/// Copy a file from the container to the host.
public func copyOut(
from source: URL,
to destination: URL,
chunkSize: Int = defaultCopyChunkSize,
progress: ProgressHandler? = nil
) async throws {
try await self.state.withLock {
let state = try $0.startedState("copyOut")

let guestPath = URL(filePath: self.root).appending(path: source.path)
try await state.vm.withAgent { agent in
try await agent.copyOut(
from: guestPath,
to: destination,
chunkSize: chunkSize,
progress: progress
)
}
}
}
}

extension VirtualMachineInstance {
Expand Down
213 changes: 213 additions & 0 deletions Sources/Containerization/SandboxContext/SandboxContext.grpc.swift

Large diffs are not rendered by default.

Loading