mirror of
				https://github.com/containers/podman.git
				synced 2025-10-31 10:00:01 +08:00 
			
		
		
		
	 5dded6fae7
			
		
	
	5dded6fae7
	
	
	
		
			
			We missed bumping the go module, so let's do it now :) * Automated go code with github.com/sirkon/go-imports-rename * Manually via `vgrep podman/v2` the rest Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package compat
 | |
| 
 | |
| import (
 | |
| 	"io/ioutil"
 | |
| 	"net/http"
 | |
| 	"os"
 | |
| 
 | |
| 	"github.com/containers/podman/v3/libpod"
 | |
| 	"github.com/containers/podman/v3/pkg/api/handlers/utils"
 | |
| 	"github.com/pkg/errors"
 | |
| )
 | |
| 
 | |
| func ExportContainer(w http.ResponseWriter, r *http.Request) {
 | |
| 	runtime := r.Context().Value("runtime").(*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, "unable to create tarball tempfile", http.StatusInternalServerError, errors.Wrap(err, "unable to create tempfile"))
 | |
| 		return
 | |
| 	}
 | |
| 	defer os.Remove(tmpfile.Name())
 | |
| 	if err := tmpfile.Close(); err != nil {
 | |
| 		utils.Error(w, "unable to close tempfile", http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
 | |
| 		return
 | |
| 	}
 | |
| 	if err := con.Export(tmpfile.Name()); err != nil {
 | |
| 		utils.Error(w, "failed to save the image", http.StatusInternalServerError, errors.Wrap(err, "failed to save image"))
 | |
| 		return
 | |
| 	}
 | |
| 	rdr, err := os.Open(tmpfile.Name())
 | |
| 	if err != nil {
 | |
| 		utils.Error(w, "failed to read temp tarball", http.StatusInternalServerError, errors.Wrap(err, "failed to read the exported tarfile"))
 | |
| 		return
 | |
| 	}
 | |
| 	defer rdr.Close()
 | |
| 	utils.WriteResponse(w, http.StatusOK, rdr)
 | |
| }
 |