fix: removed resty calls from sync (#1016)

Signed-off-by: Ana-Roberta Lisca <ana.kagome@yahoo.com>
This commit is contained in:
Lisca Ana-Roberta
2022-12-22 20:19:42 +02:00
committed by GitHub
parent 50bdc2f402
commit 14238d4a8d
12 changed files with 820 additions and 568 deletions
+1 -27
View File
@@ -6,13 +6,11 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
"sync"
"syscall"
"time"
"unicode/utf8"
@@ -66,7 +64,7 @@ func (is *ImageStoreLocal) RootDir() string {
}
func (is *ImageStoreLocal) DirExists(d string) bool {
return DirExists(d)
return common.DirExists(d)
}
// NewImageStore returns a new image store backed by a file storage.
@@ -1670,30 +1668,6 @@ func isBlobOlderThan(imgStore *ImageStoreLocal, repo string, digest godigest.Dig
return true, nil
}
func DirExists(d string) bool {
if !utf8.ValidString(d) {
return false
}
fileInfo, err := os.Stat(d)
if err != nil {
if e, ok := err.(*fs.PathError); ok && errors.Is(e.Err, syscall.ENAMETOOLONG) || //nolint: errorlint
errors.Is(e.Err, syscall.EINVAL) {
return false
}
}
if err != nil && os.IsNotExist(err) {
return false
}
if !fileInfo.IsDir() {
return false
}
return true
}
func (is *ImageStoreLocal) gcRepo(repo string) error {
dir := path.Join(is.RootDir(), repo)
+5 -4
View File
@@ -25,6 +25,7 @@ import (
. "github.com/smartystreets/goconvey/convey"
zerr "zotregistry.io/zot/errors"
"zotregistry.io/zot/pkg/common"
"zotregistry.io/zot/pkg/extensions/monitoring"
"zotregistry.io/zot/pkg/log"
"zotregistry.io/zot/pkg/storage"
@@ -482,7 +483,7 @@ func FuzzTestDeleteImageManifest(f *testing.F) {
func FuzzDirExists(f *testing.F) {
f.Fuzz(func(t *testing.T, data string) {
_ = local.DirExists(data)
_ = common.DirExists(data)
})
}
@@ -1602,7 +1603,7 @@ func TestNegativeCases(t *testing.T) {
panic(err)
}
ok := local.DirExists(filePath)
ok := common.DirExists(filePath)
So(ok, ShouldBeFalse)
})
@@ -1610,7 +1611,7 @@ func TestNegativeCases(t *testing.T) {
dir := t.TempDir()
filePath := path.Join(dir, "hi \255")
ok := local.DirExists(filePath)
ok := common.DirExists(filePath)
So(ok, ShouldBeFalse)
})
@@ -1623,7 +1624,7 @@ func TestNegativeCases(t *testing.T) {
}
}
path := builder.String()
ok := local.DirExists(path)
ok := common.DirExists(path)
So(ok, ShouldBeFalse)
})
}