Merge fixes + cleanup

This commit is contained in:
Guillaume J. Charmes 2013-05-16 11:27:50 -07:00
parent 2ae8aaa106
commit db1e965b65

View file

@ -699,15 +699,16 @@ func (srv *Server) ImageDelete(name string) error {
img, err := srv.runtime.repositories.LookupImage(name)
if err != nil {
return fmt.Errorf("No such image: %s", name)
} else {
tag := ""
}
var tag string
if strings.Contains(name, ":") {
nameParts := strings.Split(name, ":")
name = nameParts[0]
tag = nameParts[1]
}
// if the images is referenced several times
Debugf("Image %s referenced %d times", img.Id, len(srv.runtime.repositories.ById()[img.Id]))
utils.Debugf("Image %s referenced %d times", img.Id, len(srv.runtime.repositories.ById()[img.Id]))
if len(srv.runtime.repositories.ById()[img.Id]) > 1 {
// if it's repo:tag, try to delete the tag (docker rmi base:latest)
if tag != "" {
@ -715,17 +716,11 @@ func (srv *Server) ImageDelete(name string) error {
return err
}
return nil
} else {
}
// check if the image is referenced in another repo (base and user/base are the same, docker rmi user/base)
var other bool
for _, repoTag := range srv.runtime.repositories.ById()[img.Id] {
if !strings.Contains(repoTag, name+":") {
other = true
break
}
}
// if found in another repo, delete the repo, other delete the whole image (docker rmi base)
if other {
// if found in another repo, delete the repo, otherwie delete the whole image (docker rmi base)
if err := srv.runtime.repositories.Delete(name, "", img.Id); err != nil {
return err
}
@ -739,7 +734,6 @@ func (srv *Server) ImageDelete(name string) error {
if err := srv.runtime.repositories.Delete(name, tag, img.Id); err != nil {
return err
}
}
return nil
}