Skip to content

Instantly share code, notes, and snippets.

@duglin
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duglin/eca6bf5c9d1ed6cd8bc1 to your computer and use it in GitHub Desktop.
Save duglin/eca6bf5c9d1ed6cd8bc1 to your computer and use it in GitHub Desktop.
In container:
/tmp/f1
/tmp/f2
/tmp/dir/f1
/tmp/dir/f2
CMD: docker cp container:source target
Source Target Body (tar unless otherwise indicated) Stat Hdr Result
/tmp . tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat ./tmp/...
/tmp ./ tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat ./tmp/...
/tmp dir(missing) tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat ./dir/f1, dir/f2, dir/dir/f1, dir/dir/f2
/tmp dir(present) tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat ./dir/tmp/...
/tmp dir/(missing) tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat ./dir/f1, dir/f2, dir/dir/f1, dir/dir/f2
/tmp dir/(missing) tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat ./dir/tmp/...
/tmp file(present) tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat error
/tmp file/(present) tmp + tmp/f1, tmp/f2, tmp/dir/f1, tmp/dir/f2 tmp stat error
I believe the key take-away from above is that the presence or lack of a / on target doesn't matter.
Presence or absent of the target indicates whether we're creating the target or coping into the target.
I think we can determine what we're doing to do based just on the target info and the stat header (which includes a isDir flag)
Source Target Body (tar unless otherwise indicated) Stat Hdr Result
/tmp/f1 dir(present) f1 (note, no tmp info) - not a tar f1 stat ./dir/f1
/tmp/f1 dir/(present) f1 - not a tar f1 stat ./dir/f1
/tmp/f* dir f1, f2 none ./dir/f1, dir/f2
/tmp/f1 file(present) f1 - not a tar f1 stat ./dir/file
/tmp/f1 file(missing) f1 - not a tar f1 stat ./dir/file
/tmp/f* file(present) f1, f2 none error file not a dir
/tmp/f* file(missing) f1, f2 none error file not a dir
/tmp/* dir(present) f1, f2, dir/f1, dir/f2 none ./dir/f1, dir/f2, dir/dir/f1, dir/dir/f2
I think we can determine what to do in each case by only looking at what on the CLI and checking the stat header.
"none" stat header means we have more than one file in the tar.
Copying a single target that is a dir is still "one target" - meaning we have a stat header for the
dir and the tar contains lots of files.
Net:
A docker tar (tar w/o stat header) means we have more than one src, so target MUST be a dir (present).
A single src (file or dir) means we create target (if not there) and put src into it (a rename of top-most thing).
A single src (file or dir) means we copy into target (if a dir) and put src into dir (copy not a rename).
A single src (dir) means we copy error if target is a file.
A single src (file) means we copy (replace) target if its a file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment