mirror of
https://github.com/containers/podman.git
synced 2025-06-19 00:06:43 +08:00
Cleanup /libpod/images/load handler
* Remove orphaned code * Add meaningful error from LoadImageFromSingleImageArchive() when heuristic fails to determine payload format * Correct swagger to output correct types and headers Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -319,18 +319,6 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func ImagesLoad(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
query := struct {
|
||||
Reference string `schema:"reference"`
|
||||
}{
|
||||
// Add defaults here once needed.
|
||||
}
|
||||
|
||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
|
||||
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
|
||||
return
|
||||
}
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "libpod-images-load.tar")
|
||||
if err != nil {
|
||||
@ -338,14 +326,15 @@ func ImagesLoad(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
defer tmpfile.Close()
|
||||
|
||||
if _, err := io.Copy(tmpfile, r.Body); err != nil && err != io.EOF {
|
||||
_, err = io.Copy(tmpfile, r.Body)
|
||||
tmpfile.Close()
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to write archive to temporary file"))
|
||||
return
|
||||
}
|
||||
|
||||
tmpfile.Close()
|
||||
loadedImage, err := runtime.LoadImage(context.Background(), tmpfile.Name(), os.Stderr, "")
|
||||
if err != nil {
|
||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to load image"))
|
||||
|
@ -810,11 +810,14 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
|
||||
// summary: Load image
|
||||
// description: Load an image (oci-archive or docker-archive) stream.
|
||||
// parameters:
|
||||
// - in: formData
|
||||
// - in: body
|
||||
// name: upload
|
||||
// description: tarball of container image
|
||||
// type: file
|
||||
// required: true
|
||||
// description: tarball of container image
|
||||
// schema:
|
||||
// type: string
|
||||
// consumes:
|
||||
// - application/x-tar
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
|
Reference in New Issue
Block a user