From 1c94f5f53a47997f76cafb633092fce9dbdab3ea Mon Sep 17 00:00:00 2001 From: David Calavera Date: Mon, 2 Nov 2015 18:53:26 -0500 Subject: [PATCH] Decouple daemon and container to export containers. Signed-off-by: David Calavera --- daemon/container.go | 24 ------------------------ daemon/export.go | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index b17429682a..66c1a97460 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -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) diff --git a/daemon/export.go b/daemon/export.go index d470e5d584..cd31a128e4 100644 --- a/daemon/export.go +++ b/daemon/export.go @@ -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 +}