0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

fix(storage): remove unnecessary calls to storage driver

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
Petu Eusebiu 2024-05-29 20:10:11 +03:00
parent 2bb46b0562
commit 043d9c1ff7
No known key found for this signature in database
GPG key ID: 054006297EE91446

View file

@ -217,9 +217,6 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) {
// and an additional/optional BlobUploadDir in each image store // 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 // for s3 we can not create empty dirs, so we check only against index.json and oci-layout
dir := path.Join(is.rootDir, name) 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) files, err := is.storeDriver.List(dir)
if err != nil { if err != nil {
@ -239,21 +236,13 @@ func (is *ImageStore) ValidateRepo(name string) (bool, error) {
} }
for _, file := range files { for _, file := range files {
fileInfo, err := is.storeDriver.Stat(file) if strings.HasSuffix(file, "index.json") {
if err != nil { found["index.json"] = true
return false, err
} }
filename, err := filepath.Rel(dir, file) if strings.HasSuffix(file, ispec.ImageLayoutFile) {
if err != nil { found[ispec.ImageLayoutFile] = true
return false, err
} }
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 // 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 { for _, v := range found {
if !v && k != storageConstants.BlobUploadDir { if !v {
return false, nil 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 return true, nil
} }
@ -319,7 +294,8 @@ func (is *ImageStore) GetRepositories() ([]string, error) {
stores = append(stores, rel) 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 // if the root directory is not yet created then return an empty slice of repositories