diff --git a/examples/basic/testdo.sh b/examples/basic/testdo.sh index 9a7f06b..99d2db1 100755 --- a/examples/basic/testdo.sh +++ b/examples/basic/testdo.sh @@ -6,5 +6,8 @@ go build -o char ../../main.go echo "base" CHAR_DEV_MODE=true ./char do -h + +echo +echo "--------" echo "local_up" CHAR_DEV_MODE=false ./char do local_up -h diff --git a/pkg/plugins/provider/git.go b/pkg/plugins/provider/git.go index bf26be7..4869342 100644 --- a/pkg/plugins/provider/git.go +++ b/pkg/plugins/provider/git.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "strings" + "time" "git.front.kjuulh.io/kjuulh/char/pkg/schema" "golang.org/x/sync/errgroup" @@ -38,7 +39,8 @@ func (gpp *GitPluginProvider) FetchPlugins(ctx context.Context, registry string, "%s/%s", strings.TrimRight(baseDir, "/"), n.Hash(), ) - if _, err := os.Stat(dest); errors.Is(err, os.ErrNotExist) { + fileinfo, err := os.Stat(dest) + if errors.Is(err, os.ErrNotExist) { log.Printf("fetching git plugin repo: %s", n) return gpp.FetchPlugin( ctx, @@ -47,6 +49,15 @@ func (gpp *GitPluginProvider) FetchPlugins(ctx context.Context, registry string, dest, ) } + if fileinfo.ModTime().Add(time.Hour * 1).Before(time.Now()) { + log.Printf("fetching git plugin repo: %s as it is stale", n) + return gpp.FetchPlugin( + ctx, + registry, + plugin, + dest, + ) + } return nil @@ -61,15 +72,24 @@ func (gpp *GitPluginProvider) FetchPlugins(ctx context.Context, registry string, } func (gpp *GitPluginProvider) FetchPlugin(ctx context.Context, registry string, plugin *schema.CharSchemaPlugin, dest string) error { - cloneUrl, err := plugin.Opts.GetCloneUrl(ctx, registry, &schema.CloneUrlOpt{ - Protocol: schema.GitProtocolSsh, - SshUser: "git", - }, + cloneUrl, err := plugin.Opts.GetCloneUrl( + ctx, + registry, + &schema.CloneUrlOpt{ + Protocol: schema.GitProtocolSsh, + SshUser: "git", + }, ) if err != nil { return err } + if _, err := os.Stat(dest); !errors.Is(err, os.ErrNotExist) { + if err = os.RemoveAll(dest); err != nil { + return err + } + } + output, err := exec.Command( "git", "clone",