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! |
Report the actual file/content size in the success message, with the transferred (tar stream) size shown in parentheses when it differs from the content size. For copyToContainer, use localContentSize() which performs fast stat-only metadata lookups on local files. For copyFromContainer, use the PathStat.Size from the container API response for regular files, falling back to the tar stream size for directories. When content size equals transferred size (e.g. directory downloads or stdin input where content size is unknown), only the single size is shown to avoid redundant output. Example output: Successfully copied 0B (transferred 1.54kB) to my-container:/empty Successfully copied 5B (transferred 2.05kB) to my-container:/file Successfully copied 10.5kB to /local/dir Fixes docker#5777 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