check if the image to delete isn't parent of another

Upstream-commit: d7673274d22140dc6dfa288351f1d4d2e2fa4b63
Component: engine
This commit is contained in:
Victor Vieux
2013-05-18 14:29:32 +00:00
parent 29dcb6fe8f
commit 4708f50419

View File

@ -729,6 +729,15 @@ func (srv *Server) ImageDelete(name string) error {
}
}
}
// check is the image to delete isn't parent of another image
images, _ := srv.runtime.graph.All()
for _, image := range images {
if imgParent, err := image.GetParent(); err == nil && imgParent != nil {
if imgParent.Id == img.Id {
return fmt.Errorf("Can't delete %s, otherwise %s will be broken", name, image.ShortId())
}
}
}
if err := srv.runtime.graph.Delete(img.Id); err != nil {
return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
}