Do not support wildcards on cp
* symlink processing and wildcarding led to unexpected files being copied Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
parent
20772182e6
commit
a6836eae52
|
@ -52,7 +52,7 @@ func init() {
|
||||||
cpCommand.Command = _cpCommand
|
cpCommand.Command = _cpCommand
|
||||||
flags := cpCommand.Flags()
|
flags := cpCommand.Flags()
|
||||||
flags.BoolVar(&cpCommand.Extract, "extract", false, "Extract the tar file into the destination directory.")
|
flags.BoolVar(&cpCommand.Extract, "extract", false, "Extract the tar file into the destination directory.")
|
||||||
flags.BoolVar(&cpCommand.Pause, "pause", false, "Pause the container while copying")
|
flags.BoolVar(&cpCommand.Pause, "pause", true, "Pause the container while copying")
|
||||||
cpCommand.SetHelpTemplate(HelpTemplate())
|
cpCommand.SetHelpTemplate(HelpTemplate())
|
||||||
cpCommand.SetUsageTemplate(UsageTemplate())
|
cpCommand.SetUsageTemplate(UsageTemplate())
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,6 @@ func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest strin
|
||||||
|
|
||||||
hostOwner := idtools.IDPair{UID: int(hostUID), GID: int(hostGID)}
|
hostOwner := idtools.IDPair{UID: int(hostUID), GID: int(hostGID)}
|
||||||
|
|
||||||
var glob []string
|
|
||||||
if isFromHostToCtr {
|
if isFromHostToCtr {
|
||||||
if isVol, volDestName, volName := isVolumeDestName(destPath, ctr); isVol {
|
if isVol, volDestName, volName := isVolumeDestName(destPath, ctr); isVol {
|
||||||
path, err := pathWithVolumeMount(ctr, runtime, volDestName, volName, destPath)
|
path, err := pathWithVolumeMount(ctr, runtime, volDestName, volName, destPath)
|
||||||
|
@ -209,13 +208,7 @@ func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest strin
|
||||||
srcPath = cleanedPath
|
srcPath = cleanedPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glob, err = filepath.Glob(srcPath)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "invalid glob %q", srcPath)
|
|
||||||
}
|
|
||||||
if len(glob) == 0 {
|
|
||||||
glob = append(glob, srcPath)
|
|
||||||
}
|
|
||||||
if !filepath.IsAbs(destPath) {
|
if !filepath.IsAbs(destPath) {
|
||||||
dir, err := os.Getwd()
|
dir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -224,19 +217,11 @@ func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest strin
|
||||||
destPath = filepath.Join(dir, destPath)
|
destPath = filepath.Join(dir, destPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastError error
|
if src == "-" {
|
||||||
for _, src := range glob {
|
srcPath = os.Stdin.Name()
|
||||||
if src == "-" {
|
extract = true
|
||||||
src = os.Stdin.Name()
|
|
||||||
extract = true
|
|
||||||
}
|
|
||||||
err := copy(src, destPath, dest, idMappingOpts, &destOwner, extract, isFromHostToCtr)
|
|
||||||
if lastError != nil {
|
|
||||||
logrus.Error(lastError)
|
|
||||||
}
|
|
||||||
lastError = err
|
|
||||||
}
|
}
|
||||||
return lastError
|
return copy(srcPath, destPath, dest, idMappingOpts, &destOwner, extract, isFromHostToCtr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUser(mountPoint string, userspec string) (specs.User, error) {
|
func getUser(mountPoint string, userspec string) (specs.User, error) {
|
||||||
|
|
|
@ -223,7 +223,7 @@ var _ = Describe("Podman cp", func() {
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"cp", "testctr:testfile", "testfile1"})
|
session = podmanTest.Podman([]string{"cp", "--pause=false", "testctr:testfile", "testfile1"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ var _ = Describe("Podman cp", func() {
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(strings.Contains(string(cmdRet), "testuser")).To(BeFalse())
|
Expect(strings.Contains(string(cmdRet), "testuser")).To(BeFalse())
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"cp", "testfile1", "testctr:testfile2"})
|
session = podmanTest.Podman([]string{"cp", "--pause=false", "testfile1", "testctr:testfile2"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,8 @@ load helpers
|
||||||
"echo $rand_content1 >/tmp/$rand_filename1;
|
"echo $rand_content1 >/tmp/$rand_filename1;
|
||||||
echo $rand_content2 >/tmp/$rand_filename2"
|
echo $rand_content2 >/tmp/$rand_filename2"
|
||||||
|
|
||||||
run_podman cp 'cpcontainer:/tmp/*' $dstdir
|
# cp no longer supports wildcarding
|
||||||
|
run_podman 125 cp 'cpcontainer:/tmp/*' $dstdir
|
||||||
test -e $dstdir/$rand_filename1 || die "file 1 not copied from container"
|
|
||||||
test -e $dstdir/$rand_filename2 || die "file 2 not copied from container"
|
|
||||||
|
|
||||||
is "$(<$dstdir/$rand_filename1)" "$rand_content1" "content of file 1"
|
|
||||||
is "$(<$dstdir/$rand_filename2)" "$rand_content2" "content of file 2"
|
|
||||||
|
|
||||||
run_podman rm cpcontainer
|
run_podman rm cpcontainer
|
||||||
}
|
}
|
||||||
|
@ -150,13 +145,13 @@ load helpers
|
||||||
|
|
||||||
# Copy file from host into container, into a file named 'x'
|
# Copy file from host into container, into a file named 'x'
|
||||||
# Note that the second has a trailing slash; this will trigger mkdir
|
# Note that the second has a trailing slash; this will trigger mkdir
|
||||||
run_podman cp $srcdir/$rand_filename1 cpcontainer:/tmp/d1/x
|
run_podman cp --pause=false $srcdir/$rand_filename1 cpcontainer:/tmp/d1/x
|
||||||
is "$output" "" "output from podman cp 1"
|
is "$output" "" "output from podman cp 1"
|
||||||
|
|
||||||
run_podman cp $srcdir/$rand_filename2 cpcontainer:/tmp/d2/x/
|
run_podman cp --pause=false $srcdir/$rand_filename2 cpcontainer:/tmp/d2/x/
|
||||||
is "$output" "" "output from podman cp 3"
|
is "$output" "" "output from podman cp 3"
|
||||||
|
|
||||||
run_podman cp $srcdir/$rand_filename3 cpcontainer:/tmp/d3/x
|
run_podman cp --pause=false $srcdir/$rand_filename3 cpcontainer:/tmp/d3/x
|
||||||
is "$output" "" "output from podman cp 3"
|
is "$output" "" "output from podman cp 3"
|
||||||
|
|
||||||
# Read back.
|
# Read back.
|
||||||
|
@ -205,7 +200,7 @@ load helpers
|
||||||
"mkdir -p $graphroot; trap 'exit 0' 15;while :;do sleep 0.5;done"
|
"mkdir -p $graphroot; trap 'exit 0' 15;while :;do sleep 0.5;done"
|
||||||
|
|
||||||
# Copy from host into container.
|
# Copy from host into container.
|
||||||
run_podman cp $srcdir/$rand_filename cpcontainer:$graphroot/$rand_filename
|
run_podman cp --pause=false $srcdir/$rand_filename cpcontainer:$graphroot/$rand_filename
|
||||||
|
|
||||||
# ls, and confirm it's there.
|
# ls, and confirm it's there.
|
||||||
run_podman exec cpcontainer ls -l $graphroot/$rand_filename
|
run_podman exec cpcontainer ls -l $graphroot/$rand_filename
|
||||||
|
|
Loading…
Reference in New Issue