mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
docker rmi -r: remove all images matching a regexp
This commit is contained in:
parent
711e29fb9b
commit
74c88fdbc0
2 changed files with 38 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -209,6 +210,32 @@ func (index *Index) Delete(name string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// DeleteMatch deletes all images whose name matches `pattern`
|
||||
func (index *Index) DeleteMatch(pattern string) error {
|
||||
// Load
|
||||
if err := index.load(); err != nil {
|
||||
return err
|
||||
}
|
||||
for name, history := range index.ByName {
|
||||
if match, err := regexp.MatchString(pattern, name); err != nil {
|
||||
return err
|
||||
} else if match {
|
||||
fmt.Printf("Match: %s %s\n", name, pattern)
|
||||
// Remove from index lookup
|
||||
for _, image := range *history {
|
||||
delete(index.ById, image.Id)
|
||||
}
|
||||
// Remove from name lookup
|
||||
delete(index.ByName, name)
|
||||
}
|
||||
}
|
||||
// Save
|
||||
if err := index.save(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (index *Index) Names() []string {
|
||||
if err := index.load(); err != nil {
|
||||
return []string{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue