|
|
|
@ -17,14 +17,17 @@ limitations under the License.
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
"syscall"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
|
|
|
|
|
|
"github.com/gofrs/flock"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
"k8s.io/helm/pkg/getter"
|
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
|
"k8s.io/helm/pkg/repo"
|
|
|
|
@ -133,20 +136,13 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lock the repository file for concurrent processes synchronization and re-read its content before updating it
|
|
|
|
|
fd, err := syscall.Open(home.RepositoryFile(), syscall.O_CREAT|syscall.O_RDWR|syscall.O_CLOEXEC, 0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
fileLock := flock.New(home.RepositoryFile())
|
|
|
|
|
lockCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
|
|
|
|
defer cancel()
|
|
|
|
|
locked, err := fileLock.TryLockContext(lockCtx, time.Second)
|
|
|
|
|
if err == nil && locked {
|
|
|
|
|
defer fileLock.Unlock()
|
|
|
|
|
}
|
|
|
|
|
defer syscall.Close(fd)
|
|
|
|
|
|
|
|
|
|
flock := syscall.Flock_t{
|
|
|
|
|
Type: syscall.F_WRLCK,
|
|
|
|
|
Start: 0,
|
|
|
|
|
Len: 0,
|
|
|
|
|
Whence: io.SeekStart,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
syscall.FcntlFlock(uintptr(fd), syscall.F_SETLK, &flock)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|