Repository navigation
container/cp: don't print success message when copy fails - #7515
Conversation
| reportedSize := copiedSize | ||
| if !cpRes.Stat.Mode.IsDir() { | ||
| reportedSize = cpRes.Stat.Size | ||
| if res == nil { |
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.
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.
|
Thanks for updating; could you;
|
|
Thanks for the fix! I tested |
317a13c to
ee70962
Compare
|
Thanks for the pointers — all three addressed in the new head commit ee70962:
No code changes — the tree is identical to the previous head. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Looks like a linter isn't happy now 😢 |
ee70962 to
07910e5
Compare
|
Pushed a fix (added some |
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. Also rename the res variable in copyFromContainer to err: it 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: Xiong Han <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
07910e5 to
25552ba
Compare
|
Derp; one |
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.