From f2821756dbb0f325b0427f7c2c0cdcac1ae7283a Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 7 Mar 2024 22:32:28 -0700 Subject: [PATCH] Lock tool during repo setup --- pkg/repos/get.go | 4 ++++ pkg/repos/git/cmd.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/repos/get.go b/pkg/repos/get.go index 43c7e160..db96dc8a 100644 --- a/pkg/repos/get.go +++ b/pkg/repos/get.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" + "github.com/BurntSushi/locker" "github.com/gptscript-ai/gptscript/pkg/repos/git" "github.com/gptscript-ai/gptscript/pkg/types" ) @@ -52,6 +53,9 @@ func New(cacheDir string, runtimes ...Runtime) *Manager { } func (m *Manager) setup(ctx context.Context, runtime Runtime, tool types.Tool, env []string) (string, []string, error) { + locker.Lock(tool.ID) + defer locker.Unlock(tool.ID) + target := filepath.Join(m.storageDir, tool.Source.Repo.Revision, runtime.ID()) targetFinal := filepath.Join(target, tool.Source.Repo.Path) doneFile := target + ".done" diff --git a/pkg/repos/git/cmd.go b/pkg/repos/git/cmd.go index 2f724a55..7bbf0ecb 100644 --- a/pkg/repos/git/cmd.go +++ b/pkg/repos/git/cmd.go @@ -19,7 +19,8 @@ func cloneBare(ctx context.Context, repo, toDir string) error { } func gitWorktreeAdd(ctx context.Context, gitDir, commitDir, commit string) error { - cmd := newGitCommand(ctx, "--git-dir", gitDir, "worktree", "add", "-f", commitDir, commit) + // The double -f is intentional + cmd := newGitCommand(ctx, "--git-dir", gitDir, "worktree", "add", "-f", "-f", commitDir, commit) return cmd.Run() }