remove buffer
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
564e6bc780
commit
177f658882
3 changed files with 11 additions and 30 deletions
26
api.go
26
api.go
|
@ -668,31 +668,11 @@ func deleteImages(srv *Server, version float64, w http.ResponseWriter, r *http.R
|
|||
if vars == nil {
|
||||
return fmt.Errorf("Missing parameter")
|
||||
}
|
||||
var (
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
job = srv.Eng.Job("image_delete", vars["name"])
|
||||
)
|
||||
job.Stdout.Add(buffer)
|
||||
var job = srv.Eng.Job("image_delete", vars["name"])
|
||||
job.Stdout.Add(w)
|
||||
job.SetenvBool("autoPrune", version > 1.1)
|
||||
if err := job.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outs := engine.NewTable("", 0)
|
||||
if _, err := outs.ReadFrom(buffer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(outs.Data) != 0 {
|
||||
var err error
|
||||
if version < 1.9 {
|
||||
_, err = outs.WriteTo(w)
|
||||
} else {
|
||||
_, err = outs.WriteListTo(w)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("Conflict, %s wasn't deleted", vars["name"])
|
||||
return job.Run()
|
||||
}
|
||||
|
||||
func postContainersStart(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
|
|
@ -823,13 +823,13 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
|
|||
|
||||
var encounteredError error
|
||||
for _, name := range cmd.Args() {
|
||||
body, _, err := readBody(cli.call("DELETE", "/images/"+name, nil, false))
|
||||
stream, _, err := cli.call("DELETE", "/images/"+name, nil, false)
|
||||
if err != nil {
|
||||
fmt.Fprintf(cli.err, "%s\n", err)
|
||||
encounteredError = fmt.Errorf("Error: failed to remove one or more images")
|
||||
} else {
|
||||
outs := engine.NewTable("Created", 0)
|
||||
if _, err := outs.ReadFrom(bytes.NewReader(body)); err != nil {
|
||||
if _, err := outs.ReadListFrom(stream); err != nil {
|
||||
fmt.Fprintf(cli.err, "%s\n", err)
|
||||
encounteredError = fmt.Errorf("Error: failed to remove one or more images")
|
||||
continue
|
||||
|
|
11
server.go
11
server.go
|
@ -99,6 +99,7 @@ func jobInitApi(job *engine.Job) engine.Status {
|
|||
"build": srv.Build,
|
||||
"pull": srv.ImagePull,
|
||||
"import": srv.ImageImport,
|
||||
"image_delete": srv.ImageDelete,
|
||||
} {
|
||||
if err := job.Eng.Register(name, handler); err != nil {
|
||||
job.Error(err)
|
||||
|
@ -336,10 +337,6 @@ func (srv *Server) ImageExport(job *engine.Job) engine.Status {
|
|||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if err := job.Eng.Register("image_delete", srv.ImageDelete); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
|
@ -1971,7 +1968,11 @@ func (srv *Server) ImageDelete(job *engine.Job) engine.Status {
|
|||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if _, err := imgs.WriteTo(job.Stdout); err != nil {
|
||||
if len(imgs.Data) == 0 {
|
||||
job.Errorf("Conflict, %s wasn't deleted", job.Args[0])
|
||||
return engine.StatusErr
|
||||
}
|
||||
if _, err := imgs.WriteListTo(job.Stdout); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue