From 7d81733af747f210cd9c06cfdc2e26ef41a7edfe 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] 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> (cherry picked from commit f091b9cc01afff97d285775fb4a7cfa899ec1d4d) --- 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 52cd020f5..e07eb8685 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -112,7 +112,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)