mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00

This allows use to use STDOUT directly without having to call open again, also this makes the export API endpoint much more performant since it no longer needs to copy to a temp file. I noticed that there was no export API test so I added one. And lastly opening /dev/stdout will not work on windows. Fixes #16870 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
31 lines
825 B
Go
31 lines
825 B
Go
package compat
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/containers/podman/v4/libpod"
|
|
"github.com/containers/podman/v4/pkg/api/handlers/utils"
|
|
api "github.com/containers/podman/v4/pkg/api/types"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
// set the correct header
|
|
w.Header().Set("Content-Type", "application/x-tar")
|
|
// NOTE: As described in w.Write() it automatically sets the http code to
|
|
// 200 on first write if no other code was set.
|
|
|
|
if err := con.Export(w); err != nil {
|
|
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to export container: %w", err))
|
|
return
|
|
}
|
|
}
|