0
Fork 0
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:
Ramkumar Chinchani 2021-08-09 23:08:55 +00:00 committed by Ramkumar Chinchani
parent 53b5fa6493
commit 63b88d0e57
2 changed files with 15 additions and 4 deletions

View file

@ -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 {

View file

@ -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) {