Add container copy/cp command for host-container file transfer#1190
Add container copy/cp command for host-container file transfer#1190simone-panico wants to merge 8 commits intoapple:mainfrom
Conversation
|
Related to #232 |
Sources/Services/ContainerAPIService/Client/ContainerClient.swift
Outdated
Show resolved
Hide resolved
Sources/Services/ContainerAPIService/Client/ContainerClient.swift
Outdated
Show resolved
Hide resolved
Sources/Services/ContainerAPIService/Server/Containers/ContainersService.swift
Show resolved
Hide resolved
Sources/Services/ContainerAPIService/Server/Containers/ContainersService.swift
Show resolved
Hide resolved
| let request = XPCMessage(route: SandboxRoutes.copyIn.rawValue) | ||
| request.set(key: SandboxKeys.sourcePath.rawValue, value: source) | ||
| request.set(key: SandboxKeys.destinationPath.rawValue, value: destination) | ||
| request.set(key: SandboxKeys.fileMode.rawValue, value: UInt64(mode)) |
There was a problem hiding this comment.
Because the set Method in XPCMessage.swift expects a UInt64
There was a problem hiding this comment.
Do you want to handle it differently? I looked at the code again and couldn't find a better option
|
⏺ Scenario 1:
Scenario 2:
Scenario 3: src with /, dst without / (src must be an existing directory)
Scenario 4: src with /, dst with / (src must be an existing directory & dst must be a directory if existing)
|
|
Hi @simone-panico The bold italic phrases are what is different from desired behavior (i.e., docker) now, and can be addressed. Below is general comments.
|
|
|
||
| static func parsePathRef(_ ref: String) -> PathRef { | ||
| let parts = ref.components(separatedBy: ":") | ||
| if parts.count == 2 { |
There was a problem hiding this comment.
How about this?
let parts = ref.components(separatedBy: ":")
switch parts.count {
case 1:
return .local(ref)
case 2 where !parts[0].isEmpty && parts[1].starts(with: "/"):
return .container(id: parts[0], path: parts[1])
default:
throw ContainerizationError(.invalidArgument, message: "invalid path given: \(ref)")
}
| let srcRef = Self.parsePathRef(source) | ||
| let dstRef = Self.parsePathRef(destination) | ||
|
|
||
| switch (srcRef, dstRef) { |
There was a problem hiding this comment.
We need a sanitization logic here to check local path.
-
If
localPathis source
a. Check if file or directory atlocalPathexists.
b. IflocalPathends with/, check it's directory. -
If
localPathis dest
a. IflocalPathends with/, need to check if it's not existing or a directory.
Then, we need to extend destURL correctly following the comment I left.
Type of Change
Motivation and Context
Adds the
container copy(aliased ascp) command to copy files between a running container and the local filesystem.I saw #1023 and the feedback from @dcantah — the previous attempt relied on tar being installed inside the container.
This implementation takes the recommended approach:
file transfers go through the guest agent via the existing
copyIn/copyOutmethods on the coreContainerization, with no dependency on container tooling.Testing