From f091b9cc01afff97d285775fb4a7cfa899ec1d4d Mon Sep 17 00:00:00 2001 From: Leon Bentrup <4458913+xanecs@users.noreply.github.com> Date: Tue, 6 Oct 2020 10:42:34 +0200 Subject: [PATCH 1/2] Correctly determine repository-config lockfile path helm repo add automatically creates a lockfile based on the repository config file path When the given filepath did not include a file extension, a lockfile in a nonexistent directory would have been created. Signed-off-by: Leon Bentrup <4458913+xanecs@users.noreply.github.com> --- cmd/helm/repo_add.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index f79c213c0..c56ed595a 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -95,7 +95,14 @@ func (o *repoAddOptions) run(out io.Writer) error { } // Acquire a file lock for process synchronization - fileLock := flock.New(strings.Replace(o.repoFile, filepath.Ext(o.repoFile), ".lock", 1)) + repoFileExt := filepath.Ext(o.repoFile) + var lockPath string + if len(repoFileExt) > 0 && len(repoFileExt) < len(o.repoFile) { + lockPath = strings.Replace(o.repoFile, repoFileExt, ".lock", 1) + } else { + lockPath = o.repoFile + ".lock" + } + fileLock := flock.New(lockPath) lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() locked, err := fileLock.TryLockContext(lockCtx, time.Second) From ccada716eea605060440788244d528edd29c8a6f Mon Sep 17 00:00:00 2001 From: Leon Bentrup <4458913+xanecs@users.noreply.github.com> Date: Wed, 7 Oct 2020 08:45:07 +0200 Subject: [PATCH 2/2] Add Test cases for repository-config without file extension Signed-off-by: Leon Bentrup <4458913+xanecs@users.noreply.github.com> --- cmd/helm/repo_add_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/helm/repo_add_test.go b/cmd/helm/repo_add_test.go index f3bc54985..739173ee7 100644 --- a/cmd/helm/repo_add_test.go +++ b/cmd/helm/repo_add_test.go @@ -142,6 +142,18 @@ func TestRepoAddConcurrentDirNotExist(t *testing.T) { repoAddConcurrent(t, testName, repoFile) } +func TestRepoAddConcurrentNoFileExtension(t *testing.T) { + const testName = "test-name-3" + repoFile := filepath.Join(ensure.TempDir(t), "repositories") + repoAddConcurrent(t, testName, repoFile) +} + +func TestRepoAddConcurrentHiddenFile(t *testing.T) { + const testName = "test-name-4" + repoFile := filepath.Join(ensure.TempDir(t), ".repositories") + repoAddConcurrent(t, testName, repoFile) +} + func repoAddConcurrent(t *testing.T, testName, repoFile string) { ts, err := repotest.NewTempServerWithCleanup(t, "testdata/testserver/*.*") if err != nil {