From d9eab2f6d06136f495ba52314db79080d0cbbed6 Mon Sep 17 00:00:00 2001 From: mudler Date: Fri, 10 Feb 2023 21:39:12 +0100 Subject: [PATCH] Wait until download is finished --- api/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/api.go b/api/api.go index 6e822cf..6a60a3b 100644 --- a/api/api.go +++ b/api/api.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "os" + "path/filepath" "regexp" "strings" "sync" @@ -59,6 +60,9 @@ func (a *API) downloadImage(image, dst string) error { os.MkdirAll(dst, os.ModePerm) a.mu.Unlock() + os.WriteFile(filepath.Join(dst, ".lock"), []byte{}, 0600) + defer os.RemoveAll(filepath.Join(dst, ".lock")) + pterm.Info.Printfln("Downloading %s to %s", image, dst) ref, err := name.ParseReference(image) if err != nil { @@ -192,6 +196,10 @@ func (a *API) renderImage(c echo.Context, image, strip string) error { return c.HTML(202, "Processing the request, try again soon.") } + if _, err := os.Stat(filepath.Join(a.cacheStore.Path(h.Hex), ".lock")); err == nil { + return c.HTML(202, "Still processing, try again soon.") + } + pterm.Info.Printfln("Render from cache %s: %s Size: %s", h.Hex, image, units.HumanSize(float64(size))) return echo.WrapHandler(