From 0d4856c4b1ef0118dd69413ef7e17ddb2d5cc870 Mon Sep 17 00:00:00 2001 From: HolgerHuo Date: Thu, 23 Nov 2023 00:38:50 -0800 Subject: [PATCH] fix: metadata not updated when remote file changes (#297) --- handler/remote.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/handler/remote.go b/handler/remote.go index dc1c699..f2da42c 100644 --- a/handler/remote.go +++ b/handler/remote.go @@ -84,9 +84,16 @@ func fetchRemoteImg(url string, subdir string) config.MetaFile { localRawImagePath := path.Join(config.RemoteRaw, subdir, metadata.Id) if !helper.ImageExists(localRawImagePath) || metadata.Checksum != helper.HashString(etag) { - // remote file has changed or local file not exists - log.Info("Remote file not found in remote-raw, re-fetching...") cleanProxyCache(path.Join(config.Config.ExhaustPath, subdir, metadata.Id+"*")) + if metadata.Checksum != helper.HashString(etag) { + // remote file has changed + log.Info("Remote file changed, updating metadata and fetching image source...") + helper.DeleteMetadata(url, subdir) + helper.WriteMetadata(url, etag, subdir) + } else { + // local file not exists + log.Info("Remote file not found in remote-raw, re-fetching...") + } downloadFile(localRawImagePath, url) } return metadata