Skip to content

Fix container cp rejecting paths that contain a colon - #1970

Open
OrtegaMatias wants to merge 1 commit into
apple:mainfrom
OrtegaMatias:fix/cp-colon-in-path
Open

Fix container cp rejecting paths that contain a colon#1970
OrtegaMatias wants to merge 1 commit into
apple:mainfrom
OrtegaMatias:fix/cp-colon-in-path

Conversation

@OrtegaMatias

Copy link
Copy Markdown

Type of Change

  • Bug fix

Motivation and Context

container cp rejected a container:path reference whenever the path contained a colon — e.g. an ISO-8601 timestamp filename such as /var/log/app-2026-07-20T10:30:00.log — failing with invalid path given even though the file exists. docker cp splits the reference on the first colon only.

Fixes #1969.

Description

ContainerCopy.parsePathRef used components(separatedBy: ":") and rejected any reference producing more than two parts. It now:

  • splits on the first colon only — a container id never contains a path separator, but the path may contain colons; and
  • treats a reference whose pre-colon segment contains / as a local path, which additionally lets local paths containing a colon be copied.

Error behavior for genuinely invalid references (empty id, non-absolute container path) is unchanged. PathRef is now Equatable to support the added unit tests.

Testing

Added Tests/ContainerCommandsTests/ContainerCopyPathRefTests.swift covering: a plain local path, a container reference, a container path containing colons (the regression), a local path containing colons, an empty id, and a non-absolute container path.

Transparency note: I was unable to run the in-repo test suite locally — this machine only has an Xcode 27 beta toolchain (which fails building a transitive dependency under strict concurrency) and the Command Line Tools, which lack the test frameworks. I verified the parser change in isolation against all the cases above and confirmed it compiles as part of the ContainerCommands target. CI runs the added tests.

`ContainerCopy.parsePathRef` split a "<id>:<path>" reference on every
colon and rejected anything with more than one part, so `container cp`
failed with "invalid path given" on a container path whose filename
contains a colon — e.g. an ISO-8601 timestamp such as
/var/log/app-2026-07-20T10:30:00.log (the file exists; only the parse
fails).

Split on the first colon only — a container id never contains a path
separator, but the path may contain colons — and treat a reference whose
pre-colon part contains '/' as a local path. This also lets local paths
that contain a colon be copied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container cp fails with "invalid path given" when a path contains a colon

1 participant