diff --git a/store.go b/store.go index feb9311336..25767b7a2f 100644 --- a/store.go +++ b/store.go @@ -2115,6 +2115,37 @@ func (s *store) SetNames(id string, names []string) error { return ristore.SetNames(id, deduped) } + // Check is id refers to a RO Store + ristores, err := s.ROImageStores() + if err != nil { + return err + } + for _, s := range ristores { + store := s + store.RLock() + defer store.Unlock() + if modified, err := store.Modified(); modified || err != nil { + if err = store.Load(); err != nil { + return err + } + } + if i, err := store.Get(id); err == nil { + // Unlock R/O lock and lock with R/W lock + // Previous defer.Unlock() will free the new lock. + ristore.Unlock() + ristore.Lock() + if len(deduped) > 1 { + // Do not want to create image name in R/W storage + deduped = deduped[1:] + } + _, err := ristore.Create(id, deduped, i.TopLayer, i.Metadata, i.Created, i.Digest) + if err == nil { + return ristore.Save() + } + return err + } + } + rcstore, err := s.ContainerStore() if err != nil { return err diff --git a/tests/stores.bats b/tests/stores.bats index d15d047cf1..dbe99e3d69 100644 --- a/tests/stores.bats +++ b/tests/stores.bats @@ -106,6 +106,11 @@ load helpers [ "$status" -eq 0 ] [ "$output" != "" ] + run storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root add-names -n newimage $lowerimage + [ "$status" -eq 0 ] + run storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root delete-image newimage + [ "$status" -eq 0 ] + # Create a container based on the lowerimage. run storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root --debug=false create-container "$lowerimage" [ "$status" -eq 0 ]