Skip to content

Commit

Permalink
Wait until download is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Feb 10, 2023
1 parent da6942c commit d9eab2f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d9eab2f

Please sign in to comment.