mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Decouple daemon and container to export containers.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
9f79cfdb2f
commit
1c94f5f53a
2 changed files with 27 additions and 25 deletions
|
@ -356,30 +356,6 @@ func (container *Container) Resize(h, w int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) export() (archive.Archive, error) {
|
||||
if err := container.Mount(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uidMaps, gidMaps := container.daemon.GetUIDGIDMaps()
|
||||
archive, err := archive.TarWithOptions(container.basefs, &archive.TarOptions{
|
||||
Compression: archive.Uncompressed,
|
||||
UIDMaps: uidMaps,
|
||||
GIDMaps: gidMaps,
|
||||
})
|
||||
if err != nil {
|
||||
container.Unmount()
|
||||
return nil, err
|
||||
}
|
||||
arch := ioutils.NewReadCloserWrapper(archive, func() error {
|
||||
err := archive.Close()
|
||||
container.Unmount()
|
||||
return err
|
||||
})
|
||||
container.logEvent("export")
|
||||
return arch, err
|
||||
}
|
||||
|
||||
// Mount sets container.basefs
|
||||
func (container *Container) Mount() error {
|
||||
return container.daemon.Mount(container)
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"io"
|
||||
|
||||
derr "github.com/docker/docker/errors"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
)
|
||||
|
||||
// ContainerExport writes the contents of the container to the given
|
||||
|
@ -14,7 +16,7 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
|
|||
return err
|
||||
}
|
||||
|
||||
data, err := container.export()
|
||||
data, err := daemon.containerExport(container)
|
||||
if err != nil {
|
||||
return derr.ErrorCodeExportFailed.WithArgs(name, err)
|
||||
}
|
||||
|
@ -26,3 +28,27 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) containerExport(container *Container) (archive.Archive, error) {
|
||||
if err := daemon.Mount(container); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uidMaps, gidMaps := daemon.GetUIDGIDMaps()
|
||||
archive, err := archive.TarWithOptions(container.basefs, &archive.TarOptions{
|
||||
Compression: archive.Uncompressed,
|
||||
UIDMaps: uidMaps,
|
||||
GIDMaps: gidMaps,
|
||||
})
|
||||
if err != nil {
|
||||
daemon.unmount(container)
|
||||
return nil, err
|
||||
}
|
||||
arch := ioutils.NewReadCloserWrapper(archive, func() error {
|
||||
err := archive.Close()
|
||||
container.Unmount()
|
||||
return err
|
||||
})
|
||||
daemon.logContainerEvent(container, "export")
|
||||
return arch, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue