Unverified Commit 52a3cdb8 authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #6694 from bacongobbler/fix-6682-helm2

fix(cmd): acquire file lock on repository.lock
parents 07c17133 0a2d5845
......@@ -20,6 +20,8 @@ import (
"context"
"fmt"
"io"
"path/filepath"
"strings"
"syscall"
"time"
......@@ -135,8 +137,10 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
return fmt.Errorf("Looks like %q is not a valid chart repository or cannot be reached: %s", url, err.Error())
}
// Lock the repository file for concurrent goroutines or processes synchronization
fileLock := flock.New(home.RepositoryFile())
repoFile := home.RepositoryFile()
// Acquire a file lock for process synchronization
fileLock := flock.New(strings.Replace(repoFile, filepath.Ext(repoFile), ".lock", 1))
lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
locked, err := fileLock.TryLockContext(lockCtx, time.Second)
......@@ -149,12 +153,12 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
// Re-read the repositories file before updating it as its content may have been changed
// by a concurrent execution after the first read and before being locked
f, err = repo.LoadRepositoriesFile(home.RepositoryFile())
f, err = repo.LoadRepositoriesFile(repoFile)
if err != nil {
return err
}
f.Update(&c)
return f.WriteFile(home.RepositoryFile(), 0644)
return f.WriteFile(repoFile, 0644)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment