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,46 +699,40 @@ func (srv *Server) ImageDelete(name string) error {
img, err := srv.runtime.repositories.LookupImage(name) img, err := srv.runtime.repositories.LookupImage(name)
if err != nil { if err != nil {
return fmt.Errorf("No such image: %s", name) return fmt.Errorf("No such image: %s", name)
} else { }
tag := "" var tag string
if strings.Contains(name, ":") { if strings.Contains(name, ":") {
nameParts := strings.Split(name, ":") nameParts := strings.Split(name, ":")
name = nameParts[0] name = nameParts[0]
tag = nameParts[1] tag = nameParts[1]
}
// if the images is referenced several times
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 != "" {
if err := srv.runtime.repositories.Delete(name, tag, img.Id); err != nil {
return err
}
return nil
} }
// if the images is referenced several times // check if the image is referenced in another repo (base and user/base are the same, docker rmi user/base)
Debugf("Image %s referenced %d times", img.Id, len(srv.runtime.repositories.ById()[img.Id])) for _, repoTag := range srv.runtime.repositories.ById()[img.Id] {
if len(srv.runtime.repositories.ById()[img.Id]) > 1 { if !strings.Contains(repoTag, name+":") {
// if it's repo:tag, try to delete the tag (docker rmi base:latest) // if found in another repo, delete the repo, otherwie delete the whole image (docker rmi base)
if tag != "" { if err := srv.runtime.repositories.Delete(name, "", img.Id); err != nil {
if err := srv.runtime.repositories.Delete(name, tag, img.Id); err != nil {
return err return err
} }
return nil 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 err := srv.runtime.repositories.Delete(name, "", img.Id); err != nil {
return err
}
return nil
}
} }
} }
if err := srv.runtime.graph.Delete(img.Id); err != nil { }
return fmt.Errorf("Error deleting image %s: %s", name, err.Error()) if err := srv.runtime.graph.Delete(img.Id); err != nil {
} return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
if err := srv.runtime.repositories.Delete(name, tag, img.Id); err != nil { }
return err if err := srv.runtime.repositories.Delete(name, tag, img.Id); err != nil {
} return err
} }
return nil return nil
} }