mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
pkg/storage: fix partially initialized repo storage
Thanks shimish2 for the unit test. Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
parent
53b5fa6493
commit
63b88d0e57
2 changed files with 15 additions and 4 deletions
|
@ -148,10 +148,6 @@ func (is *ImageStore) Unlock() {
|
|||
func (is *ImageStore) initRepo(name string) error {
|
||||
repoDir := path.Join(is.rootDir, name)
|
||||
|
||||
if fi, err := os.Stat(repoDir); err == nil && fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// create "blobs" subdir
|
||||
err := ensureDir(path.Join(repoDir, "blobs"), is.log)
|
||||
if err != nil {
|
||||
|
|
|
@ -523,6 +523,21 @@ func TestNegativeCases(t *testing.T) {
|
|||
err = il.InitRepo("test")
|
||||
So(err, ShouldNotBeNil)
|
||||
}
|
||||
|
||||
err = os.Chmod(dir, 0755)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Init repo should fail if repo is a file.
|
||||
err = ioutil.WriteFile(path.Join(dir, "file-test"), []byte("this is test file"), 0755) // nolint:gosec
|
||||
So(err, ShouldBeNil)
|
||||
err = il.InitRepo("file-test")
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
err = os.Mkdir(path.Join(dir, "test-dir"), 0755)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = il.InitRepo("test-dir")
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
Convey("Invalid validate repo", t, func(c C) {
|
||||
|
|
Loading…
Reference in a new issue