fix(cmd): acquire repository.lock

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
pull/6692/head
Matthew Fisher 5 years ago
parent c3e356faba
commit 4d6a2461f3
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -23,6 +23,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/gofrs/flock"
@ -85,8 +86,8 @@ func (o *repoAddOptions) run(out io.Writer) error {
return err
}
// Lock the repository file for concurrent goroutines or processes synchronization
fileLock := flock.New(o.repoFile)
// Acquire a file lock for process synchronization
fileLock := flock.New(strings.Replace(o.repoFile, filepath.Ext(o.repoFile), ".lock", 1))
lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
locked, err := fileLock.TryLockContext(lockCtx, time.Second)

Loading…
Cancel
Save