fix(cp): resolve relative host paths against current directory
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
- [x] 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
- [x] Tested locally — builds and all existing tests pass
- [ ] Added/updated tests
- [ ] Added/updated docs
@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:
- print destination path on successful copy
- add tests for relative source and destination paths.
@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.
@JaewonHur I mistakenly forgot to add the commit signatures so should I add them?
Yeah please :) Could you sign your commits?
@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.
Yeah. Seems fine, but could you just roll back .github/workflows/common.yml?
Just do git checkout main .github/workflows/common.yml and commit.
Hi, @JaewonHur, I checked out .github/workflows/common.yml from upstream/main and committed it. The workflow file now matches upstream exactly. Please check now.
Thanks. Let me merge once all tests are done.
Code Coverage
| Tier | Line Coverage |
|---|---|
| Unit | 33.35% |
| Integration | 23.02% |
| Combined | 55.52% |
@JaewonHur Thank you so much for your cooperation and patience throughout the process of merging my PR. I truly appreciate your support. Please feel free to reach out if there's ever anything I can assist you with in the future.