fetcher: rely on "latest" symlink as fallback
2 files changed, 14 insertions(+), 9 deletions(-)
M domain/content/fetcher/fetcher.go → domain/content/fetcher/fetcher.go
@@ -77,7 +77,9 @@ err, fmsg.With(fmt.Sprintf("could not parse numeric filename %s", name)), ) } - if v < f.current-1 { + if f.current > 1 && v < f.current-1 { + f.log.Info("cleaning old revision", "version", v) + err := os.RemoveAll(filepath.Join(f.options.Root, name)) if err != nil { return fault.Wrap(err, fmsg.With("could not remove folder"))@@ -201,6 +203,10 @@ }() } func (f *Fetcher) makeURL(runID, basename string) string { + if runID == "1" { + runID = "latest" + } + return f.options.FetchURL.JoinPath(runID, basename).String() }@@ -271,11 +277,11 @@ func (f *Fetcher) getCurrentVersion() (uint64, error) { target, err := os.Readlink(filepath.Join(f.options.Root, "current")) if err != nil && errors.Is(err, fs.ErrNotExist) { - return 0, fault.Wrap(err, fmsg.With("could not stat current link")) + return 1, fault.Wrap(err, fmsg.With("could not stat current link")) } f.current, err = strconv.ParseUint(target, 10, 64) if err != nil { - return 0, fault.Wrap( + return 1, fault.Wrap( err, fmsg.With(fmt.Sprintf("unexpected symlink target (current -> %s)", target)), )@@ -293,7 +299,7 @@ f.log.Debug("versions", "current", f.current, "latest", latest) defer f.cleanOldRevisionsAsync() - if latest > f.current { + if f.current >= 1 || latest > f.current { err = f.getArtefacts(latest) if err != nil { return latest, fault.Wrap(err, fmsg.With("could not fetch artefacts"))