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:
parent
19ba0b851b
commit
3f3f5f0bba
3 changed files with 16 additions and 3 deletions
13
runtime.go
13
runtime.go
|
@ -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") == "" {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue