mirror of
https://github.com/containers/podman.git
synced 2025-12-02 02:58:03 +08:00
vendor containers/storage@main
Mainly to pull in fixes for #1382 which is impossible to reproduce locally so let's optimistically mark it as fixed and reopen if needed in the future. Fixes: #1382 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
67
vendor/github.com/containers/storage/images.go
generated
vendored
67
vendor/github.com/containers/storage/images.go
generated
vendored
@@ -94,11 +94,11 @@ type Image struct {
|
||||
Flags map[string]interface{} `json:"flags,omitempty"`
|
||||
}
|
||||
|
||||
// ROImageStore provides bookkeeping for information about Images.
|
||||
type ROImageStore interface {
|
||||
ROFileBasedStore
|
||||
ROMetadataStore
|
||||
ROBigDataStore
|
||||
// roImageStore provides bookkeeping for information about Images.
|
||||
type roImageStore interface {
|
||||
roFileBasedStore
|
||||
roMetadataStore
|
||||
roBigDataStore
|
||||
|
||||
// Exists checks if there is an image with the given ID or name.
|
||||
Exists(id string) bool
|
||||
@@ -106,10 +106,6 @@ type ROImageStore interface {
|
||||
// Get retrieves information about an image given an ID or name.
|
||||
Get(id string) (*Image, error)
|
||||
|
||||
// Lookup attempts to translate a name to an ID. Most methods do this
|
||||
// implicitly.
|
||||
Lookup(name string) (string, error)
|
||||
|
||||
// Images returns a slice enumerating the known images.
|
||||
Images() ([]Image, error)
|
||||
|
||||
@@ -120,13 +116,13 @@ type ROImageStore interface {
|
||||
ByDigest(d digest.Digest) ([]*Image, error)
|
||||
}
|
||||
|
||||
// ImageStore provides bookkeeping for information about Images.
|
||||
type ImageStore interface {
|
||||
ROImageStore
|
||||
RWFileBasedStore
|
||||
RWMetadataStore
|
||||
RWImageBigDataStore
|
||||
FlaggableStore
|
||||
// rwImageStore provides bookkeeping for information about Images.
|
||||
type rwImageStore interface {
|
||||
roImageStore
|
||||
rwFileBasedStore
|
||||
rwMetadataStore
|
||||
rwImageBigDataStore
|
||||
flaggableStore
|
||||
|
||||
// Create creates an image that has a specified ID (or a random one) and
|
||||
// optional names, using the specified layer as its topmost (hopefully
|
||||
@@ -299,7 +295,7 @@ func (r *imageStore) Load() error {
|
||||
return ErrDuplicateImageNames
|
||||
}
|
||||
r.images = images
|
||||
r.idindex = truncindex.NewTruncIndex(idlist)
|
||||
r.idindex = truncindex.NewTruncIndex(idlist) // Invalid values in idlist are ignored: they are not a reason to refuse processing the whole store.
|
||||
r.byid = ids
|
||||
r.byname = names
|
||||
r.bydigest = digests
|
||||
@@ -324,11 +320,13 @@ func (r *imageStore) Save() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Touch()
|
||||
return ioutils.AtomicWriteFile(rpath, jdata, 0600)
|
||||
if err := ioutils.AtomicWriteFile(rpath, jdata, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
return r.Touch()
|
||||
}
|
||||
|
||||
func newImageStore(dir string) (ImageStore, error) {
|
||||
func newImageStore(dir string) (rwImageStore, error) {
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -336,8 +334,6 @@ func newImageStore(dir string) (ImageStore, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lockfile.Lock()
|
||||
defer lockfile.Unlock()
|
||||
istore := imageStore{
|
||||
lockfile: lockfile,
|
||||
dir: dir,
|
||||
@@ -346,19 +342,19 @@ func newImageStore(dir string) (ImageStore, error) {
|
||||
byname: make(map[string]*Image),
|
||||
bydigest: make(map[digest.Digest][]*Image),
|
||||
}
|
||||
istore.Lock()
|
||||
defer istore.Unlock()
|
||||
if err := istore.Load(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &istore, nil
|
||||
}
|
||||
|
||||
func newROImageStore(dir string) (ROImageStore, error) {
|
||||
func newROImageStore(dir string) (roImageStore, error) {
|
||||
lockfile, err := GetROLockfile(filepath.Join(dir, "images.lock"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lockfile.RLock()
|
||||
defer lockfile.Unlock()
|
||||
istore := imageStore{
|
||||
lockfile: lockfile,
|
||||
dir: dir,
|
||||
@@ -367,6 +363,8 @@ func newROImageStore(dir string) (ROImageStore, error) {
|
||||
byname: make(map[string]*Image),
|
||||
bydigest: make(map[digest.Digest][]*Image),
|
||||
}
|
||||
istore.RLock()
|
||||
defer istore.Unlock()
|
||||
if err := istore.Load(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -455,7 +453,9 @@ func (r *imageStore) Create(id string, names []string, layer, metadata string, c
|
||||
return nil, fmt.Errorf("validating digests for new image: %w", err)
|
||||
}
|
||||
r.images = append(r.images, image)
|
||||
r.idindex.Add(id)
|
||||
// This can only fail on duplicate IDs, which shouldn’t happen — and in that case the index is already in the desired state anyway.
|
||||
// Implementing recovery from an unlikely and unimportant failure here would be too risky.
|
||||
_ = r.idindex.Add(id)
|
||||
r.byid[id] = image
|
||||
for _, name := range names {
|
||||
r.byname[name] = image
|
||||
@@ -572,7 +572,9 @@ func (r *imageStore) Delete(id string) error {
|
||||
}
|
||||
}
|
||||
delete(r.byid, id)
|
||||
r.idindex.Delete(id)
|
||||
// This can only fail if the ID is already missing, which shouldn’t happen — and in that case the index is already in the desired state anyway.
|
||||
// The store’s Delete method is used on various paths to recover from failures, so this should be robust against partially missing data.
|
||||
_ = r.idindex.Delete(id)
|
||||
for _, name := range image.Names {
|
||||
delete(r.byname, name)
|
||||
}
|
||||
@@ -608,13 +610,6 @@ func (r *imageStore) Get(id string) (*Image, error) {
|
||||
return nil, fmt.Errorf("locating image with ID %q: %w", id, ErrImageUnknown)
|
||||
}
|
||||
|
||||
func (r *imageStore) Lookup(name string) (id string, err error) {
|
||||
if image, ok := r.lookup(name); ok {
|
||||
return image.ID, nil
|
||||
}
|
||||
return "", fmt.Errorf("locating image with ID %q: %w", id, ErrImageUnknown)
|
||||
}
|
||||
|
||||
func (r *imageStore) Exists(id string) bool {
|
||||
_, ok := r.lookup(id)
|
||||
return ok
|
||||
@@ -798,10 +793,6 @@ func (r *imageStore) Lock() {
|
||||
r.lockfile.Lock()
|
||||
}
|
||||
|
||||
func (r *imageStore) RecursiveLock() {
|
||||
r.lockfile.RecursiveLock()
|
||||
}
|
||||
|
||||
func (r *imageStore) RLock() {
|
||||
r.lockfile.RLock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user