export: use io.Writer instead of file

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>
This commit is contained in:
Paul Holzinger
2022-12-19 19:45:06 +01:00
parent 56982a9236
commit 3ac5d10098
7 changed files with 37 additions and 47 deletions

View File

@ -462,7 +462,7 @@ func (c *Container) Unpause() error {
// Export exports a container's root filesystem as a tar archive
// The archive will be saved as a file at the given path
func (c *Container) Export(path string) error {
func (c *Container) Export(out io.Writer) error {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@ -477,7 +477,7 @@ func (c *Container) Export(path string) error {
}
defer c.newContainerEvent(events.Mount)
return c.export(path)
return c.export(out)
}
// AddArtifact creates and writes to an artifact file for the container