diff --git a/daemon/copy.go b/daemon/copy.go new file mode 100644 index 0000000000..9d18b010c0 --- /dev/null +++ b/daemon/copy.go @@ -0,0 +1,33 @@ +package daemon + +import ( + "io" + + "github.com/docker/docker/engine" +) + +func (daemon *Daemon) ContainerCopy(job *engine.Job) engine.Status { + if len(job.Args) != 2 { + return job.Errorf("Usage: %s CONTAINER RESOURCE\n", job.Name) + } + + var ( + name = job.Args[0] + resource = job.Args[1] + ) + + if container := daemon.Get(name); container != nil { + + data, err := container.Copy(resource) + if err != nil { + return job.Error(err) + } + defer data.Close() + + if _, err := io.Copy(job.Stdout, data); err != nil { + return job.Error(err) + } + return engine.StatusOK + } + return job.Errorf("No such container: %s", name) +} diff --git a/daemon/daemon.go b/daemon/daemon.go index d632d8b20c..b6ee5e7afd 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -152,6 +152,9 @@ func (daemon *Daemon) Install(eng *engine.Engine) error { if err := eng.Register("delete", daemon.ContainerDestroy); err != nil { return err } + if err := eng.Register("container_copy", daemon.ContainerCopy); err != nil { + return err + } return nil } diff --git a/server/container.go b/server/container.go index 2c13e8d447..441d21624e 100644 --- a/server/container.go +++ b/server/container.go @@ -7,7 +7,6 @@ package server import ( "errors" "fmt" - "io" "os/exec" "strconv" "strings" @@ -218,29 +217,3 @@ func (srv *Server) Containers(job *engine.Job) engine.Status { } return engine.StatusOK } - -func (srv *Server) ContainerCopy(job *engine.Job) engine.Status { - if len(job.Args) != 2 { - return job.Errorf("Usage: %s CONTAINER RESOURCE\n", job.Name) - } - - var ( - name = job.Args[0] - resource = job.Args[1] - ) - - if container := srv.daemon.Get(name); container != nil { - - data, err := container.Copy(resource) - if err != nil { - return job.Error(err) - } - defer data.Close() - - if _, err := io.Copy(job.Stdout, data); err != nil { - return job.Error(err) - } - return engine.StatusOK - } - return job.Errorf("No such container: %s", name) -} diff --git a/server/init.go b/server/init.go index d37a21fbc1..fb011ff4ad 100644 --- a/server/init.go +++ b/server/init.go @@ -86,24 +86,23 @@ func InitServer(job *engine.Job) engine.Status { job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon) for name, handler := range map[string]engine.Handler{ - "tag": srv.ImageTag, // FIXME merge with "image_tag" - "info": srv.DockerInfo, - "image_export": srv.ImageExport, - "images": srv.Images, - "history": srv.ImageHistory, - "viz": srv.ImagesViz, - "container_copy": srv.ContainerCopy, - "log": srv.Log, - "changes": srv.ContainerChanges, - "top": srv.ContainerTop, - "load": srv.ImageLoad, - "build": srv.Build, - "pull": srv.ImagePull, - "import": srv.ImageImport, - "image_delete": srv.ImageDelete, - "events": srv.Events, - "push": srv.ImagePush, - "containers": srv.Containers, + "tag": srv.ImageTag, // FIXME merge with "image_tag" + "info": srv.DockerInfo, + "image_export": srv.ImageExport, + "images": srv.Images, + "history": srv.ImageHistory, + "viz": srv.ImagesViz, + "log": srv.Log, + "changes": srv.ContainerChanges, + "top": srv.ContainerTop, + "load": srv.ImageLoad, + "build": srv.Build, + "pull": srv.ImagePull, + "import": srv.ImageImport, + "image_delete": srv.ImageDelete, + "events": srv.Events, + "push": srv.ImagePush, + "containers": srv.Containers, } { if err := job.Eng.Register(name, srv.handlerWrap(handler)); err != nil { return job.Error(err)