Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/credentials/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
)

type CredentialHelperDirs struct {
RevisionFile, BinDir, RepoDir string
RevisionFile, LastCheckedFile, BinDir, RepoDir string
}

func GetCredentialHelperDirs(cacheDir string) CredentialHelperDirs {
return CredentialHelperDirs{
RevisionFile: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "revision"),
BinDir: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "bin"),
RepoDir: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "repo"),
RevisionFile: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "revision"),
LastCheckedFile: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "last-checked"),
BinDir: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "bin"),
RepoDir: filepath.Join(cacheDir, "repos", "gptscript-credential-helpers", "repo"),
}
}
20 changes: 20 additions & 0 deletions pkg/repos/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"sync"
"time"

"github.com/BurntSushi/locker"
"github.com/gptscript-ai/gptscript/pkg/config"
Expand Down Expand Up @@ -112,11 +113,30 @@ func (m *Manager) deferredSetUpCredentialHelpers(ctx context.Context, cliCfg *co
locker.Lock("gptscript-credential-helpers")
defer locker.Unlock("gptscript-credential-helpers")

// Load the last-checked file to make sure we haven't checked the repo in the last 24 hours.
now := time.Now()
lastChecked, err := os.ReadFile(m.credHelperDirs.LastCheckedFile)
if err == nil {
if t, err := time.Parse(time.RFC3339, strings.TrimSpace(string(lastChecked))); err == nil && now.Sub(t) < 24*time.Hour {
// Make sure the binary still exists, and if it does, return.
if _, err := os.Stat(filepath.Join(m.credHelperDirs.BinDir, "gptscript-credential-"+helperName+suffix)); err == nil {
log.Debugf("Credential helper %s up-to-date as of %v, checking for updates after %v", helperName, t, t.Add(24*time.Hour))
return nil
}
}
}

// Load the credential helpers repo information.
_, repo, _, err := github.Load(ctx, nil, credentialHelpersRepo)
if err != nil {
return err
}

// Update the last-checked file.
if err := os.WriteFile(m.credHelperDirs.LastCheckedFile, []byte(now.Format(time.RFC3339)), 0644); err != nil {
return err
}

var needsBuild bool

// Check the last revision shasum and see if it is different from the current one.
Expand Down