From 63b88d0e57034a85e1a390c65e1cc843bb6b7889 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Mon, 9 Aug 2021 23:08:55 +0000 Subject: [PATCH] pkg/storage: fix partially initialized repo storage Thanks shimish2 for the unit test. Signed-off-by: Ramkumar Chinchani --- pkg/storage/storage.go | 4 ---- pkg/storage/storage_test.go | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 9e8f9200..5b27d8af 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -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 { diff --git a/pkg/storage/storage_test.go b/pkg/storage/storage_test.go index fe6c93fb..6cf7b5f2 100644 --- a/pkg/storage/storage_test.go +++ b/pkg/storage/storage_test.go @@ -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) {