1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Move "copy" to daemon/copy.go

This is part of an effort to break apart the deprecated server/ package

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-07-31 21:15:28 +00:00 committed by Tibor Vass
parent cc39d579f5
commit 06229a4b76
4 changed files with 53 additions and 45 deletions

33
daemon/copy.go Normal file
View file

@ -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)
}

View file

@ -152,6 +152,9 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
if err := eng.Register("delete", daemon.ContainerDestroy); err != nil { if err := eng.Register("delete", daemon.ContainerDestroy); err != nil {
return err return err
} }
if err := eng.Register("container_copy", daemon.ContainerCopy); err != nil {
return err
}
return nil return nil
} }

View file

@ -7,7 +7,6 @@ package server
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
@ -218,29 +217,3 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
} }
return engine.StatusOK 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)
}

View file

@ -86,24 +86,23 @@ func InitServer(job *engine.Job) engine.Status {
job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon) job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon)
for name, handler := range map[string]engine.Handler{ for name, handler := range map[string]engine.Handler{
"tag": srv.ImageTag, // FIXME merge with "image_tag" "tag": srv.ImageTag, // FIXME merge with "image_tag"
"info": srv.DockerInfo, "info": srv.DockerInfo,
"image_export": srv.ImageExport, "image_export": srv.ImageExport,
"images": srv.Images, "images": srv.Images,
"history": srv.ImageHistory, "history": srv.ImageHistory,
"viz": srv.ImagesViz, "viz": srv.ImagesViz,
"container_copy": srv.ContainerCopy, "log": srv.Log,
"log": srv.Log, "changes": srv.ContainerChanges,
"changes": srv.ContainerChanges, "top": srv.ContainerTop,
"top": srv.ContainerTop, "load": srv.ImageLoad,
"load": srv.ImageLoad, "build": srv.Build,
"build": srv.Build, "pull": srv.ImagePull,
"pull": srv.ImagePull, "import": srv.ImageImport,
"import": srv.ImageImport, "image_delete": srv.ImageDelete,
"image_delete": srv.ImageDelete, "events": srv.Events,
"events": srv.Events, "push": srv.ImagePush,
"push": srv.ImagePush, "containers": srv.Containers,
"containers": srv.Containers,
} { } {
if err := job.Eng.Register(name, srv.handlerWrap(handler)); err != nil { if err := job.Eng.Register(name, srv.handlerWrap(handler)); err != nil {
return job.Error(err) return job.Error(err)