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:
parent
cc39d579f5
commit
06229a4b76
4 changed files with 53 additions and 45 deletions
33
daemon/copy.go
Normal file
33
daemon/copy.go
Normal 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)
|
||||||
|
}
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -92,7 +92,6 @@ func InitServer(job *engine.Job) engine.Status {
|
||||||
"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,
|
||||||
|
|
Loading…
Reference in a new issue