From 335eeb5ed579f56b5d46b5a20c470fa68af0fcc8 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Wed, 21 Feb 2024 22:52:38 +0000 Subject: [PATCH] fix: load local archive --- cmd/kernel.go | 20 +++++++++++++++++--- container/container.go | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cmd/kernel.go b/cmd/kernel.go index 9a1daaf..a5e1cea 100644 --- a/cmd/kernel.go +++ b/cmd/kernel.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/cavaliergopher/grab/v3" "github.com/naoina/toml" "github.com/remeh/sizedwaitgroup" "github.com/rs/zerolog/log" @@ -21,6 +22,7 @@ import ( "code.dumpstack.io/tools/out-of-tree/config/dotfiles" "code.dumpstack.io/tools/out-of-tree/container" "code.dumpstack.io/tools/out-of-tree/distro" + "code.dumpstack.io/tools/out-of-tree/fs" "code.dumpstack.io/tools/out-of-tree/kernel" ) @@ -174,10 +176,22 @@ func (cmd *KernelCmd) fetchContainerCache(c container.Container) { return } - path := cache.ContainerURL(c.Name()) - err := container.Load(path, c.Name()) + tmp, err := fs.TempDir() + if err != nil { + return + } + defer os.RemoveAll(tmp) + + resp, err := grab.Get(tmp, cache.ContainerURL(c.Name())) + if err != nil { + return + } + + defer os.Remove(resp.Filename) + + err = container.Load(resp.Filename, c.Name()) if err == nil { - log.Info().Msgf("container %s -> %s", path, c.Name()) + log.Info().Msgf("use prebuilt container %s", c.Name()) } } diff --git a/container/container.go b/container/container.go index a606a84..8e4da0c 100644 --- a/container/container.go +++ b/container/container.go @@ -77,13 +77,13 @@ func Images() (diis []Image, err error) { return } -func Load(path string, name string) (err error) { +func Load(localpath string, name string) (err error) { exist := Container{name: name}.Exist() if exist && UseCache { return } - cmd := exec.Command(Runtime, "load", "-i", path) + cmd := exec.Command(Runtime, "load", "-i", localpath) log.Debug().Msgf("%v", cmd) raw, err := cmd.CombinedOutput()