mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-22 07:37:50 +00:00
podman save: fix redirect of multi-images
Fix a bug when saving multi-image archives where the progress bars from copying images was accidentally written to the archive and hence corrupted it. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
parent
fffcc25d8d
commit
78afe67e00
2 changed files with 42 additions and 6 deletions
|
|
@ -94,6 +94,7 @@ func save(cmd *cobra.Command, args []string) (finalErr error) {
|
|||
return errors.Errorf("--compress can only be set when --format is either 'oci-dir' or 'docker-dir'")
|
||||
}
|
||||
if len(saveOpts.Output) == 0 {
|
||||
saveOpts.Quiet = true
|
||||
fi := os.Stdout
|
||||
if terminal.IsTerminal(int(fi.Fd())) {
|
||||
return errors.Errorf("refusing to save to terminal. Use -o flag or redirect")
|
||||
|
|
@ -122,12 +123,6 @@ func save(cmd *cobra.Command, args []string) (finalErr error) {
|
|||
tags = args[1:]
|
||||
}
|
||||
|
||||
// Decide whether c/image's progress bars should use stderr or stdout.
|
||||
// If the output is set of stdout, any log message there would corrupt
|
||||
// the tarfile.
|
||||
if saveOpts.Output == os.Stdout.Name() {
|
||||
saveOpts.Quiet = true
|
||||
}
|
||||
err := registry.ImageEngine().Save(context.Background(), args[0], tags, saveOpts)
|
||||
if err == nil {
|
||||
succeeded = true
|
||||
|
|
|
|||
|
|
@ -147,4 +147,45 @@ verify_iid_and_name() {
|
|||
"Diagnostic from 'podman load' without redirection or -i"
|
||||
}
|
||||
|
||||
@test "podman load - multi-image archive" {
|
||||
img1="quay.io/libpod/testimage:00000000"
|
||||
img2="quay.io/libpod/testimage:20200902"
|
||||
archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar
|
||||
|
||||
run_podman pull $img1
|
||||
run_podman pull $img2
|
||||
|
||||
run_podman save -m -o $archive $img1 $img2
|
||||
run_podman rmi -f $img1 $img2
|
||||
run_podman load -i $archive
|
||||
|
||||
run_podman image exists $img1
|
||||
run_podman image exists $img2
|
||||
run_podman rmi -f $img1 $img2
|
||||
}
|
||||
|
||||
@test "podman load - multi-image archive with redirect" {
|
||||
img1="quay.io/libpod/testimage:00000000"
|
||||
img2="quay.io/libpod/testimage:20200902"
|
||||
archive=$PODMAN_TMPDIR/myimage-$(random_string 8).tar
|
||||
|
||||
run_podman pull $img1
|
||||
run_podman pull $img2
|
||||
|
||||
# We can't use run_podman because that uses the BATS 'run' function
|
||||
# which redirects stdout and stderr. Here we need to guarantee
|
||||
# that podman's stdout is a pipe, not any other form of redirection
|
||||
$PODMAN save -m $img1 $img2 | cat >$archive
|
||||
if [ "$status" -ne 0 ]; then
|
||||
die "Command failed: podman save ... | cat"
|
||||
fi
|
||||
|
||||
run_podman rmi -f $img1 $img2
|
||||
run_podman load -i $archive
|
||||
|
||||
run_podman image exists $img1
|
||||
run_podman image exists $img2
|
||||
run_podman rmi -f $img1 $img2
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue