Check read-only stores when Putting new layers

When we try to Store.Put() a new layer, also check read-only layer
stores as part of verifying that the new layer's parent is known.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2017-10-02 17:41:25 -04:00
parent cab96110cf
commit 945adfcd8d
1 changed files with 13 additions and 4 deletions

View File

@ -740,11 +740,14 @@ func (s *store) PutLayer(id, parent string, names []string, mountLabel string, w
if err != nil {
return nil, -1, err
}
rlstores, err := s.ROLayerStores()
if err != nil {
return nil, -1, err
}
rcstore, err := s.ContainerStore()
if err != nil {
return nil, -1, err
}
rlstore.Lock()
defer rlstore.Unlock()
if modified, err := rlstore.Modified(); modified || err != nil {
@ -759,9 +762,15 @@ func (s *store) PutLayer(id, parent string, names []string, mountLabel string, w
id = stringid.GenerateRandomID()
}
if parent != "" {
if l, err := rlstore.Get(parent); err == nil && l != nil {
parent = l.ID
} else {
var ilayer *Layer
for _, lstore := range append([]ROLayerStore{rlstore}, rlstores...) {
if l, err := lstore.Get(parent); err == nil && l != nil {
ilayer = l
parent = ilayer.ID
break
}
}
if ilayer == nil {
return nil, -1, ErrLayerUnknown
}
containers, err := rcstore.Containers()