Skip to content

Commit

Permalink
remove unnecessary calls to storage driver
Browse files Browse the repository at this point in the history
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
  • Loading branch information
eusebiu-constantin-petu-dbk committed May 29, 2024
1 parent 2bb46b0 commit fd8a701
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions pkg/storage/imagestore/imagestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fd8a701

Please sign in to comment.