state: moved stdlib lock to upper function to fix race condition

Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
Sam Alba
2021-12-21 14:25:18 -08:00
parent fc106e9a91
commit fdb4b94276
2 changed files with 24 additions and 20 deletions

View File

@@ -8,8 +8,6 @@ import (
"os"
"path"
"path/filepath"
"github.com/gofrs/flock"
)
var (
@@ -20,21 +18,9 @@ var (
ModuleName = "alpha.dagger.io"
EnginePackage = fmt.Sprintf("%s/europa/dagger/engine", ModuleName)
Path = path.Join("cue.mod", "pkg", ModuleName)
lockFilePath = path.Join("cue.mod", "dagger.lock")
)
func Vendor(ctx context.Context, mod string) error {
lockFilePath := path.Join(mod, lockFilePath)
fileLock := flock.New(lockFilePath)
if err := fileLock.Lock(); err != nil {
return err
}
defer func() {
fileLock.Unlock()
os.Remove(lockFilePath)
}()
// Remove any existing copy of the universe
if err := os.RemoveAll(path.Join(mod, Path)); err != nil {
return err