mirror of
				https://github.com/containers/podman.git
				synced 2025-10-31 18:08:51 +08:00 
			
		
		
		
	 7938f32c53
			
		
	
	7938f32c53
	
	
	
		
			
			This commit removes error message string from utils.Error in pkg/api. Param was not used inside a function for quite a long time [NO NEW TESTS NEEDED] Signed-off-by: Jakub Guzik <jguzik@redhat.com>
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package compat
 | |
| 
 | |
| import (
 | |
| 	"io/ioutil"
 | |
| 	"net/http"
 | |
| 	"os"
 | |
| 
 | |
| 	"github.com/containers/podman/v4/libpod"
 | |
| 	"github.com/containers/podman/v4/pkg/api/handlers/utils"
 | |
| 	api "github.com/containers/podman/v4/pkg/api/types"
 | |
| 	"github.com/pkg/errors"
 | |
| )
 | |
| 
 | |
| func ExportContainer(w http.ResponseWriter, r *http.Request) {
 | |
| 	runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
 | |
| 	name := utils.GetName(r)
 | |
| 	con, err := runtime.LookupContainer(name)
 | |
| 	if err != nil {
 | |
| 		utils.ContainerNotFound(w, name, err)
 | |
| 		return
 | |
| 	}
 | |
| 	tmpfile, err := ioutil.TempFile("", "api.tar")
 | |
| 	if err != nil {
 | |
| 		utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
 | |
| 		return
 | |
| 	}
 | |
| 	defer os.Remove(tmpfile.Name())
 | |
| 	if err := tmpfile.Close(); err != nil {
 | |
| 		utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
 | |
| 		return
 | |
| 	}
 | |
| 	if err := con.Export(tmpfile.Name()); err != nil {
 | |
| 		utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to save image"))
 | |
| 		return
 | |
| 	}
 | |
| 	rdr, err := os.Open(tmpfile.Name())
 | |
| 	if err != nil {
 | |
| 		utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
 | |
| 		return
 | |
| 	}
 | |
| 	defer rdr.Close()
 | |
| 	utils.WriteResponse(w, http.StatusOK, rdr)
 | |
| }
 |