[daemon] Refactor image_delete.go

This file was not well documented and had very high cyclomatic complexity.
This patch completely rearranges this file and the ImageDelete method to
be easier to follow and more maintainable in the future.

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
This commit is contained in:
Josh Hawn
2015-08-28 11:01:24 -07:00
parent b1cb1b1df4
commit 111d2f3487
5 changed files with 378 additions and 148 deletions
+5
View File
@@ -404,6 +404,11 @@ func (graph *Graph) ByParent() map[string][]*image.Image {
return byParent
}
// HasChildren returns whether the given image has any child images.
func (graph *Graph) HasChildren(img *image.Image) bool {
return len(graph.ByParent()[img.ID]) > 0
}
// Retain keeps the images and layers that are in the pulling chain so that
// they are not deleted. If not retained, they may be deleted by rmi.
func (graph *Graph) Retain(sessionID string, layerIDs ...string) {
+6
View File
@@ -188,6 +188,12 @@ func (store *TagStore) ByID() map[string][]string {
return byID
}
// HasReferences returns whether or not the given image is referenced in one or
// more repositories.
func (store *TagStore) HasReferences(img *image.Image) bool {
return len(store.ByID()[img.ID]) > 0
}
// ImageName returns name of an image, given the image's ID.
func (store *TagStore) ImageName(id string) string {
if names, exists := store.ByID()[id]; exists && len(names) > 0 {