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>
pull/8853/head
Leon Bentrup 4 years ago
parent fc9b46067f
commit f091b9cc01

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

Loading…
Cancel
Save