Skip to content

fix(cp): resolve relative host paths against current directory#1741

Open
adityabagchi24 wants to merge 4 commits into
apple:mainfrom
adityabagchi24:main
Open

fix(cp): resolve relative host paths against current directory#1741
adityabagchi24 wants to merge 4 commits into
apple:mainfrom
adityabagchi24:main

Conversation

@adityabagchi24

Copy link
Copy Markdown

Fixes #1738

container cp fails when the host source path is relative (e.g. container cp file foo:/root/), because NSString.standardizingPath only canonicalizes paths but does not make them absolute. The unchanged relative path is then interpreted as /file (root-absolute) by URL(fileURLWithPath:) on the runtime side.

Fixed by resolving relative paths against the current working directory before use, matching the pattern already used by container export, container image save, and container image load.

The same fix was also applied to the copy-out destination path (line 68), which had the same issue.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

container cp file foo:/root/ fails with "copyIn: source not found '/file'" because the relative path file is never expanded to an absolute path. Using $PWD/file works, but relative paths should work too — every other command in the codebase handles this correctly.

Testing

  • Tested locally — builds and all existing tests pass
  • Added/updated tests
  • Added/updated docs

@JaewonHur

Copy link
Copy Markdown
Contributor

@adityabagchi24 Hi! Could you check #1743.
Sorry for the duplicate PR, I just saw this one after opening that PR :(

I'm happy to merge this one, but could you add followings:

  1. print destination path on successful copy
  2. add tests for relative source and destination paths.

@adityabagchi24

adityabagchi24 commented Jun 18, 2026

Copy link
Copy Markdown
Author

@JaewonHur Thanks for the heads up on #1743. These are great additions and handles exceptions well. Please review mine as well. I've added the print output and integration tests as requested.

}

try await client.copyIn(id: id, source: srcPath.string, destination: path, createParents: true)
let printedDest = path.hasSuffix("/") ? "\(id):\(path)\(srcPath.lastComponent!)" : "\(id):\(path)"

@JaewonHur JaewonHur Jun 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid using force unwrap. Could you use guard to get the last component?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added guard to get the last component. Please review the changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adityabagchi24

adityabagchi24 commented Jun 18, 2026

Copy link
Copy Markdown
Author

@JaewonHur I mistakenly forgot to add the commit signatures so should I add them?

@JaewonHur

Copy link
Copy Markdown
Contributor

Yeah please :) Could you sign your commits?

@adityabagchi24 adityabagchi24 force-pushed the main branch 4 times, most recently from 5e5f53c to 6053e4d Compare June 19, 2026 04:16
@adityabagchi24

Copy link
Copy Markdown
Author

@JaewonHur

1)I have signed all my commits.
2)I had accidentally signed one of crosbymichael's commits earlier, but I have removed it. Could you please verify from your end that it has been removed?
3)After making these changes, I encountered a merge conflict in .github/workflows/common.yml. The conflict was resolved after committing the changes.

Could you please review my changes when you have a chance? Thank you.

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 copy doesn't expand host path correctly.

2 participants