mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
podman load: support downloading files
Support downloading files, for instance via `podman load -i server.com/image.tar`. The specified URL is downloaded in the frontend and stored as a temp file that gets passed down to the backend. Also vendor in c/common@main to use the new `pkg/download`. Fixes: #11970 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
31
vendor/github.com/containers/common/pkg/download/download.go
generated
vendored
Normal file
31
vendor/github.com/containers/common/pkg/download/download.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// FromURL downloads the specified source to a file in tmpdir (OS defaults if
|
||||
// empty).
|
||||
func FromURL(tmpdir, source string) (string, error) {
|
||||
tmp, err := ioutil.TempFile(tmpdir, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("creating temporary download file: %w", err)
|
||||
}
|
||||
defer tmp.Close()
|
||||
|
||||
response, err := http.Get(source) // nolint:noctx
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("downloading %s: %w", source, err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
_, err = io.Copy(tmp, response.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("copying %s to %s: %w", source, tmp.Name(), err)
|
||||
}
|
||||
|
||||
return tmp.Name(), nil
|
||||
}
|
Reference in New Issue
Block a user