Add caching
This commit is contained in:
parent
9b95267eeb
commit
fd826827f6
@ -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
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user