mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
move copy to a job
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
f213e2dd6c
commit
e2fa3f56df
2 changed files with 26 additions and 9 deletions
6
api.go
6
api.go
|
@ -1035,7 +1035,6 @@ func postContainersCopy(srv *Server, version float64, w http.ResponseWriter, r *
|
|||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
name := vars["name"]
|
||||
|
||||
copyData := &APICopy{}
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
|
@ -1054,9 +1053,10 @@ func postContainersCopy(srv *Server, version float64, w http.ResponseWriter, r *
|
|||
copyData.Resource = copyData.Resource[1:]
|
||||
}
|
||||
|
||||
if err := srv.ContainerCopy(name, copyData.Resource, w); err != nil {
|
||||
job := srv.Eng.Job("container_copy", vars["name"], copyData.Resource)
|
||||
job.Stdout.Add(w)
|
||||
if err := job.Run(); err != nil {
|
||||
utils.Errorf("%s", err.Error())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
29
server.go
29
server.go
|
@ -139,6 +139,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
|||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if err := job.Eng.Register("container_copy", srv.ContainerCopy); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
|
@ -2058,20 +2062,33 @@ func (srv *Server) ImageInspect(name string) (*Image, error) {
|
|||
return nil, fmt.Errorf("No such image: %s", name)
|
||||
}
|
||||
|
||||
func (srv *Server) ContainerCopy(name string, resource string, out io.Writer) error {
|
||||
func (srv *Server) ContainerCopy(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 2 {
|
||||
job.Errorf("Usage: %s CONTAINER RESOURCE\n", job.Name)
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
||||
var (
|
||||
name = job.Args[0]
|
||||
resource = job.Args[1]
|
||||
)
|
||||
|
||||
if container := srv.runtime.Get(name); container != nil {
|
||||
|
||||
data, err := container.Copy(resource)
|
||||
if err != nil {
|
||||
return err
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
||||
if _, err := io.Copy(out, data); err != nil {
|
||||
return err
|
||||
if _, err := io.Copy(job.Stdout, data); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return nil
|
||||
return engine.StatusOK
|
||||
}
|
||||
return fmt.Errorf("No such container: %s", name)
|
||||
job.Errorf("No such container: %s", name)
|
||||
return engine.StatusErr
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue