layerStore: clean residual resources in layerStore when remove an image

# - type: feat, fix, docs, style, refactor, test, chore
 # - scope: can be empty (eg. if the change is a global or difficult to assign to a single component)
 # - subject: start with verb (such as 'change'), 50-character line

 body: 72-character wrapped. This should answer:
 # * Why was this change necessary?
 # * How does it address the problem?
 # * Are there any side effects?

 footer:
 # - Include a link to the ticket, if any.
 # - BREAKING CHANGE

Signed-off-by: zvier <zvier20@gmail.com>
This commit is contained in:
zvier 2020-07-12 09:02:30 +08:00
parent 790eaf07bc
commit 5dcc8ed528
1 changed files with 22 additions and 0 deletions

View File

@ -1013,6 +1013,7 @@ func (r *layerStore) deleteInternal(id string) error {
if layer.MountPoint != "" {
delete(r.bymount, layer.MountPoint)
}
r.deleteInDigestMap(id)
toDeleteIndex := -1
for i, candidate := range r.layers {
if candidate.ID == id {
@ -1044,6 +1045,27 @@ func (r *layerStore) deleteInternal(id string) error {
return err
}
func (r *layerStore) deleteInDigestMap(id string) {
for digest, layers := range r.bycompressedsum {
for i, layerID := range layers {
if layerID == id {
layers = append(layers[:i], layers[i+1:]...)
r.bycompressedsum[digest] = layers
break
}
}
}
for digest, layers := range r.byuncompressedsum {
for i, layerID := range layers {
if layerID == id {
layers = append(layers[:i], layers[i+1:]...)
r.byuncompressedsum[digest] = layers
break
}
}
}
}
func (r *layerStore) Delete(id string) error {
layer, ok := r.lookup(id)
if !ok {