Skip to content

docker cp: report both content size and transferred size#6802

Draft
thaJeztah wants to merge 1 commit intodocker:masterfrom
thaJeztah:cp_size_alt
Draft

docker cp: report both content size and transferred size#6802
thaJeztah wants to merge 1 commit intodocker:masterfrom
thaJeztah:cp_size_alt

Conversation

@thaJeztah
Copy link
Member

When copying files to a container, the docker cp command would print a message reporting the size of files copied. However, this size was based on the size of the TAR stream sent, which includes the size of the TAR headers.

docker container create --name my-container busybox

touch empty-file
docker cp empty-file my-container:/empty-file
Successfully copied 1.54kB to my-container:/empty-file

This patch adds a calcTARContentSize utility, which uses the TAR headers to calculate the size of files included.

With this patch applied, the content size is reported, instead of the size of the TAR stream used for transport;

docker container create --name my-container busybox

touch empty-file
docker cp empty-file my-container:/empty-file
Successfully copied 0B (transferred 1.54kB) to my-container:/empty-file

mkdir empty-dir
docker cp ./empty-dir my-container:/somewhere/
Successfully copied 0B (transferred 1.54kB) to my-container:/somewhere/

docker cp ./cli/command my-container:/files/
Successfully copied 2.01MB (transferred 2.53MB) to my-container:/files/

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

docker cp: report both content size and transferred size

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 3.03030% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/container/cp.go 3.03% 32 Missing ⚠️

📢 Thoughts on this report? Let us know!

When copying files to a container, the `docker cp` command would print
a message reporting the size of files copied. However, this size was
based on the size of the TAR stream sent, which includes the size of
the TAR headers.

    docker container create --name my-container busybox

    touch empty-file
    docker cp empty-file my-container:/empty-file
    Successfully copied 1.54kB to my-container:/empty-file

This patch adds a `calcTARContentSize` utility, which uses the
TAR headers to calculate the size of files included.

With this patch applied, the content size is reported, instead
of the size of the TAR stream used for transport;

    docker container create --name my-container busybox

    touch empty-file
    docker cp empty-file my-container:/empty-file
    Successfully copied 0B (transferred 1.54kB) to my-container:/empty-file

    mkdir empty-dir
    docker cp ./empty-dir my-container:/somewhere/
    Successfully copied 0B (transferred 1.54kB) to my-container:/somewhere/

    docker cp ./cli/command my-container:/files/
    Successfully copied 2.01MB (transferred 2.53MB) to my-container:/files/

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker cp success message shows wrong size

2 participants