Merge pull request #8172 from rhatdan/storage

[NO TESTS NEEDED] allow the removal of storage images
This commit is contained in:
OpenShift Merge Robot
2021-03-08 23:32:34 +01:00
committed by GitHub
2 changed files with 13 additions and 0 deletions

View File

@ -325,6 +325,15 @@ func (r *Runtime) LoadImageFromSingleImageArchive(ctx context.Context, writer io
return "", errors.Wrapf(saveErr, "error pulling image") return "", errors.Wrapf(saveErr, "error pulling image")
} }
// RemoveImageFromStorage goes directly to storage and attempts to remove
// the specified image. This is dangerous and should only be done if libpod
// reports that image is not known. This call is useful if you have a corrupted
// image that was never fully added to the libpod database.
func (r *Runtime) RemoveImageFromStorage(id string) error {
_, err := r.store.DeleteImage(id, true)
return err
}
func getImageNames(images []*image.Image) string { func getImageNames(images []*image.Image) string {
var names string var names string
for i := range images { for i := range images {

View File

@ -640,6 +640,10 @@ func (ir *ImageEngine) Remove(ctx context.Context, images []string, opts entitie
for _, id := range images { for _, id := range images {
img, err := ir.Libpod.ImageRuntime().NewFromLocal(id) img, err := ir.Libpod.ImageRuntime().NewFromLocal(id)
if err != nil { if err != nil {
// attempt to remove image from storage
if forceErr := ir.Libpod.RemoveImageFromStorage(id); forceErr == nil {
continue
}
rmErrors = append(rmErrors, err) rmErrors = append(rmErrors, err)
continue continue
} }