1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Delete corresponding Devices when deleting Images

If an image is deleted and there is a corresponding device
for that image we also delete the image.
This commit is contained in:
Alexander Larsson 2013-09-06 12:04:00 +02:00 committed by Victor Vieux
parent 19ba0b851b
commit 3f3f5f0bba
3 changed files with 16 additions and 3 deletions

View file

@ -290,6 +290,19 @@ func (runtime *Runtime) Destroy(container *Container) error {
return nil
}
func (runtime *Runtime) DeleteImage(id string) error {
err := runtime.graph.Delete(id)
if err != nil {
return err
}
if runtime.GetMountMethod() == MountMethodDeviceMapper && runtime.deviceSet.HasDevice(id) {
if err := runtime.deviceSet.RemoveDevice(id); err != nil {
return fmt.Errorf("Unable to remove device for %v: %v", id, err)
}
}
return nil
}
func (runtime *Runtime) restore() error {
wheel := "-\\|/"
if os.Getenv("DEBUG") == "" && os.Getenv("TEST") == "" {

View file

@ -57,7 +57,7 @@ func cleanup(runtime *Runtime) error {
}
for _, image := range images {
if image.ID != unitTestImageID {
runtime.graph.Delete(image.ID)
runtime.DeleteImage(image.ID)
}
}
return nil

View file

@ -1025,7 +1025,7 @@ func (srv *Server) deleteImageAndChildren(id string, imgs *[]APIRmi) error {
if err := srv.runtime.repositories.DeleteAll(id); err != nil {
return err
}
err := srv.runtime.graph.Delete(id)
err := srv.runtime.DeleteImage(id)
if err != nil {
return err
}
@ -1099,7 +1099,7 @@ func (srv *Server) ImageDelete(name string, autoPrune bool) ([]APIRmi, error) {
return nil, fmt.Errorf("No such image: %s", name)
}
if !autoPrune {
if err := srv.runtime.graph.Delete(img.ID); err != nil {
if err := srv.runtime.DeleteImage(img.ID); err != nil {
return nil, fmt.Errorf("Error deleting image %s: %s", name, err)
}
return nil, nil