From cbafc197adb3021d38b482bda549fae9398414e5 Mon Sep 17 00:00:00 2001 From: Anatol Pomozov Date: Mon, 18 Nov 2024 17:40:05 -0800 Subject: [PATCH] Set modification and access times for every saved file Make sure that the file times are set even if the server did not report 'Last-Modified' --- downloader.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/downloader.go b/downloader.go index 9bd80ef..06ec8b7 100644 --- a/downloader.go +++ b/downloader.go @@ -172,10 +172,12 @@ func (d *Downloader) downloadFromUpstream(repoURL string, proxyURL *url.URL) err return err } - if !d.modificationTime.IsZero() { - if err := os.Chtimes(d.outputFileName, time.Now(), d.modificationTime); err != nil { - return err - } + modTime := d.modificationTime + if modTime.IsZero() { + modTime = time.Now() + } + if err := os.Chtimes(d.outputFileName, time.Now(), modTime); err != nil { + return err } cacheSizeGauge.WithLabelValues(d.repoName).Add(float64(d.contentLength))