From fdc32c5baadd2d3aecff28d8257aee16702ebb08 Mon Sep 17 00:00:00 2001 From: SIGSEGV Date: Wed, 13 Jan 2021 11:47:50 +0800 Subject: [PATCH] Fix the issue that the expires shortened after merging cloned mirror (#1051) Co-authored-by: Ti Prow Robot <71242396+ti-community-prow-bot@users.noreply.github.com> --- pkg/repository/v1manifest/manifest.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/repository/v1manifest/manifest.go b/pkg/repository/v1manifest/manifest.go index 01ee4a34ad..7db0eda016 100644 --- a/pkg/repository/v1manifest/manifest.go +++ b/pkg/repository/v1manifest/manifest.go @@ -420,9 +420,18 @@ func RenewManifest(m ValidManifest, startTime time.Time) { if m.Base().Version > 0 { m.Base().Version++ } - m.Base().Expires = startTime.Add( - ManifestsConfig[m.Base().Ty].Expire, - ).Format(time.RFC3339) + + // only update expire field when it's old than target expire time + targetExpire := startTime.Add(ManifestsConfig[m.Base().Ty].Expire) + currentExpire, err := time.Parse(time.RFC3339, m.Base().Expires) + if err != nil { + m.Base().Expires = targetExpire.Format(time.RFC3339) + return + } + + if currentExpire.Before(targetExpire) { + m.Base().Expires = targetExpire.Format(time.RFC3339) + } } // loadKeys stores all keys declared in manifest into ks.