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 f091b9cc01)
pull/9795/head
Leon Bentrup 4 years ago committed by Martin Hickey
parent cbd2868ac2
commit 7d81733af7

@ -112,7 +112,14 @@ func (o *repoAddOptions) run(out io.Writer) error {
} }
// Acquire a file lock for process synchronization // 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) lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
locked, err := fileLock.TryLockContext(lockCtx, time.Second) locked, err := fileLock.TryLockContext(lockCtx, time.Second)

Loading…
Cancel
Save