Repository navigation
Conversation
The non-quiet copy paths printed the "Successfully copied ..." summary unconditionally, even when the copy failed. Copying a directory onto an existing regular file therefore printed "Successfully copied 0B" before reporting "cannot copy directory". Only print the summary when the copy succeeded, in both the from-container and to-container directions. Fixes: docker#7514 Signed-off-by: xh123637 <3324733895@qq.com>
thaJeztah
reviewed
Nov 12, 2026
Comment on lines
+337
to
+342
| reportedSize := copiedSize | ||
| if !cpRes.Stat.Mode.IsDir() { | ||
| reportedSize = cpRes.Stat.Size | ||
| if res == nil { |
Member
There was a problem hiding this comment.
We should have a look at this code in general, because it's rather convoluted (definitely for a follow-up), but perhaps as part of this PR, we should consider renaming res to err - looking at the code didn't make it clear that res is just an error, not some other "result" return type.
Author
There was a problem hiding this comment.
Done — renamed res to err in copyFromContainer (commit 317a13c). Since err was already declared in this function, the CopyTo call now assigns to it directly. I left the broader cleanup of this code for a follow-up, as you suggested.
The variable only holds the error returned by archive.CopyTo, so name it err to make that clear instead of suggesting some other "result" return type. Signed-off-by: xh123637 <3324733895@qq.com>
Member
|
Thanks for updating; could you;
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #7514
Summary
docker cpprinted theSuccessfully copied ...summary unconditionally inthe non-quiet paths of both
copyFromContainerandcopyToContainer, evenwhen the copy itself failed. Copying a directory from a container onto an
existing local regular file therefore printed
Successfully copied 0B to ...before reportingcannot copy directoryand exiting with code 1.
This change only prints the summary when the copy succeeded, in both
directions. The quiet paths already returned the error without printing a
summary and are unchanged.
Release notes (optional)
Testing
New regression tests in
cli/command/container/cp_test.go:TestCopyFromContainerDoesNotReportSuccessOnFailure: copying a directoryonto an existing regular file returns
cannot copy directory, leaves thedestination unchanged, and prints no success message.
TestCopyToContainerDoesNotReportSuccessOnFailure: a failed upload printsno success message.
Both tests failed before this change (the success message was printed) and
pass after it. The existing
TestCopy*/TestRunCopy*tests incli/command/containerstill pass, andgofmtandgo vetare clean forthe changed package.
Note:
TestContainerExportOutputToFilefails in this environment both withand without this change (gid expectation mismatch), so it is unrelated to
this change. No end-to-end run against a real daemon was done.