docker cp: report both content size and transferred size#6800
docker cp: report both content size and transferred size#68004RH1T3CT0R7 wants to merge 1 commit intodocker:masterfrom
Conversation
4e6606a to
ce1c937
Compare
|
@thaJeztah Thanks for the review and the alternative approach in #6802! I looked at it carefully and updated this PR based on your feedback. Here are my thoughts: Adopted your format idea: Agreed that showing both content and transferred size is useful - updated the message to On "double traversal": On "race condition": This race exists identically in Comparing the two approaches:
Happy to make any further adjustments! |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
When copying files with `docker cp`, the success message now shows both
the actual content size and the transferred (tar stream) size when they
differ, making it easier to understand compression and overhead:
Successfully copied 2.01MB (transferred 2.53MB) to ctr:/dir
Extract copySummary helper to keep copyToContainer under the gocyclo
complexity threshold. Add unit tests for copySummary and stdin path.
Signed-off-by: 4RH1T3CT0R7 <iprintercanon@gmail.com>
Summary
docker cpsuccess message, with the transferred (tar stream) size shown in parenthesescopyToContainer()usinglocalContentSize()— fast stat-only metadata lookups on local files (zero goroutines, zero io.Pipes)copyFromContainer()usingcpRes.Stat.Sizefrom the container API for regular files, falling back to tar stream size for directoriesFixes #5777
Example output
How it works
copyToContainer:localContentSize()walks the local filesystem usingos.Lstat/filepath.WalkDir(stat-only, no data reads). This is a separate, fast metadata pass that completes in single-digit milliseconds even for 1000+ files. No goroutines, noio.Pipe, no tar parsing overhead.copyFromContainer: For regular files, uses the exact size fromcpRes.Stat.Size(already returned by the Docker API, zero cost). For directories, falls back to the tar stream size as the best available approximation.Test plan
TestCopyFromContainerReportsFileSize— 5-byte file reports "Successfully copied 5B"TestCopyToContainerReportsFileSize— 5-byte file reports "Successfully copied 5B"TestCopyToContainerReportsEmptyFileSize— empty file reports "Successfully copied 0B"TestCopyToContainerReportsDirectorySize— directory with 6 bytes total reports "Successfully copied 6B"TestCopyFromContainerReportsDirectorySize— directory from container uses transferred size