mod/stdlib: attempt to remove the lock file after file unlock
Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
parent
1b401dbc86
commit
7450c70214
17
mod/mod.go
17
mod/mod.go
@ -2,6 +2,7 @@ package mod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -36,12 +37,16 @@ func Install(ctx context.Context, workspace, repoName, versionConstraint string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fileLock := flock.New(path.Join(workspace, lockFilePath))
|
fileLockPath := path.Join(workspace, lockFilePath)
|
||||||
|
fileLock := flock.New(fileLockPath)
|
||||||
if err := fileLock.Lock(); err != nil {
|
if err := fileLock.Lock(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fileLock.Unlock()
|
defer func() {
|
||||||
|
fileLock.Unlock()
|
||||||
|
os.Remove(fileLockPath)
|
||||||
|
}()
|
||||||
|
|
||||||
err = modfile.install(ctx, require)
|
err = modfile.install(ctx, require)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -91,12 +96,16 @@ func Update(ctx context.Context, workspace, repoName, versionConstraint string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fileLock := flock.New(path.Join(workspace, lockFilePath))
|
fileLockPath := path.Join(workspace, lockFilePath)
|
||||||
|
fileLock := flock.New(fileLockPath)
|
||||||
if err := fileLock.Lock(); err != nil {
|
if err := fileLock.Lock(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fileLock.Unlock()
|
defer func() {
|
||||||
|
fileLock.Unlock()
|
||||||
|
os.Remove(fileLockPath)
|
||||||
|
}()
|
||||||
|
|
||||||
updatedRequire, err := modfile.updateToLatest(ctx, require)
|
updatedRequire, err := modfile.updateToLatest(ctx, require)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,12 +23,16 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Vendor(ctx context.Context, mod string) error {
|
func Vendor(ctx context.Context, mod string) error {
|
||||||
fileLock := flock.New(path.Join(mod, lockFilePath))
|
lockFilePath := path.Join(mod, lockFilePath)
|
||||||
|
fileLock := flock.New(lockFilePath)
|
||||||
if err := fileLock.Lock(); err != nil {
|
if err := fileLock.Lock(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fileLock.Unlock()
|
defer func() {
|
||||||
|
fileLock.Unlock()
|
||||||
|
os.Remove(lockFilePath)
|
||||||
|
}()
|
||||||
|
|
||||||
// Remove any existing copy of the universe
|
// Remove any existing copy of the universe
|
||||||
if err := os.RemoveAll(path.Join(mod, Path)); err != nil {
|
if err := os.RemoveAll(path.Join(mod, Path)); err != nil {
|
||||||
|
Reference in New Issue
Block a user