From 043d9c1ff79bc3b283813588e19a2369dbdee2d6 Mon Sep 17 00:00:00 2001 From: Petu Eusebiu Date: Wed, 29 May 2024 20:10:11 +0300 Subject: [PATCH] fix(storage): remove unnecessary calls to storage driver Signed-off-by: Petu Eusebiu --- pkg/storage/imagestore/imagestore.go | 40 ++++++---------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/pkg/storage/imagestore/imagestore.go b/pkg/storage/imagestore/imagestore.go index 69708b22..edbd2275 100644 --- a/pkg/storage/imagestore/imagestore.go +++ b/pkg/storage/imagestore/imagestore.go @@ -217,9 +217,6 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) { // and an additional/optional BlobUploadDir in each image store // for s3 we can not create empty dirs, so we check only against index.json and oci-layout dir := path.Join(is.rootDir, name) - if fi, err := is.storeDriver.Stat(dir); err != nil || !fi.IsDir() { - return false, zerr.ErrRepoNotFound - } files, err := is.storeDriver.List(dir) if err != nil { @@ -239,21 +236,13 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) { } for _, file := range files { - fileInfo, err := is.storeDriver.Stat(file) - if err != nil { - return false, err + if strings.HasSuffix(file, "index.json") { + found["index.json"] = true } - filename, err := filepath.Rel(dir, file) - if err != nil { - return false, err + if strings.HasSuffix(file, ispec.ImageLayoutFile) { + found[ispec.ImageLayoutFile] = true } - - if filename == "blobs" && !fileInfo.IsDir() { - return false, nil - } - - found[filename] = true } // check blobs dir exists only for filesystem, in s3 we can't have empty dirs @@ -263,26 +252,12 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) { } } - for k, v := range found { - if !v && k != storageConstants.BlobUploadDir { + for _, v := range found { + if !v { return false, nil } } - buf, err := is.storeDriver.ReadFile(path.Join(dir, ispec.ImageLayoutFile)) - if err != nil { - return false, err - } - - var il ispec.ImageLayout - if err := json.Unmarshal(buf, &il); err != nil { - return false, err - } - - if il.Version != ispec.ImageLayoutVersion { - return false, zerr.ErrRepoBadVersion - } - return true, nil } @@ -319,7 +294,8 @@ func (is *ImageStore) GetRepositories() ([]string, error) { stores = append(stores, rel) - return nil + // skip additional sub dirs + return driver.ErrSkipDir }) // if the root directory is not yet created then return an empty slice of repositories