diff --git a/mod/mod.go b/mod/mod.go index 22c841f5..79f9ac46 100644 --- a/mod/mod.go +++ b/mod/mod.go @@ -41,6 +41,8 @@ func Install(ctx context.Context, workspace, repoName, versionConstraint string) return nil, err } + defer fileLock.Unlock() + err = modfile.install(ctx, require) if err != nil { return nil, err @@ -50,10 +52,6 @@ func Install(ctx context.Context, workspace, repoName, versionConstraint string) return nil, err } - if err := fileLock.Unlock(); err != nil { - return nil, err - } - return require, nil } @@ -98,6 +96,8 @@ func Update(ctx context.Context, workspace, repoName, versionConstraint string) return nil, err } + defer fileLock.Unlock() + updatedRequire, err := modfile.updateToLatest(ctx, require) if err != nil { return nil, err @@ -107,10 +107,6 @@ func Update(ctx context.Context, workspace, repoName, versionConstraint string) return nil, err } - if err := fileLock.Unlock(); err != nil { - return nil, err - } - return updatedRequire, nil }