summaryrefslogtreecommitdiff
path: root/cmd/podman/images/import.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-07-22 09:31:53 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-07-23 10:21:37 +0200
commitdcb5c92c0d94c81f0706cd282b55a2a9d1fde30f (patch)
tree964a8fc0f95ce13a630fda943d039ad4f4a74a59 /cmd/podman/images/import.go
parent6370622444676db812cbc54aef56e691ea7788d0 (diff)
downloadpodman-dcb5c92c0d94c81f0706cd282b55a2a9d1fde30f.tar.gz
podman-dcb5c92c0d94c81f0706cd282b55a2a9d1fde30f.tar.bz2
podman-dcb5c92c0d94c81f0706cd282b55a2a9d1fde30f.zip
import: write stdin to tmp file
If importing an archive via stdin write it to a temporary file such that the temporary file can be opened multiple times later on. Otherwise, we may end up with an empty image. Also fix a bug in the URL parsing code; we need to check whether there's actually a scheme. Add system tests for `podman import` exercising the basics. Fixes: #10994 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'cmd/podman/images/import.go')
-rw-r--r--cmd/podman/images/import.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/cmd/podman/images/import.go b/cmd/podman/images/import.go
index bed2d4105..bc80417cc 100644
--- a/cmd/podman/images/import.go
+++ b/cmd/podman/images/import.go
@@ -3,6 +3,9 @@ package images
import (
"context"
"fmt"
+ "io"
+ "io/ioutil"
+ "os"
"strings"
"github.com/containers/common/pkg/completion"
@@ -97,6 +100,22 @@ func importCon(cmd *cobra.Command, args []string) error {
default:
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
}
+
+ if source == "-" {
+ outFile, err := ioutil.TempFile("", "podman")
+ if err != nil {
+ return errors.Errorf("error creating file %v", err)
+ }
+ defer os.Remove(outFile.Name())
+ defer outFile.Close()
+
+ _, err = io.Copy(outFile, os.Stdin)
+ if err != nil {
+ return errors.Errorf("error copying file %v", err)
+ }
+ source = outFile.Name()
+ }
+
errFileName := parse.ValidateFileName(source)
errURL := parse.ValidURL(source)
if errURL == nil {