From 6da36c66ab5ffd1dba5c5c602d5deb241bf192fe Mon Sep 17 00:00:00 2001 From: Ales Teska Date: Tue, 15 Oct 2024 13:18:10 +0200 Subject: [PATCH] When libsreg directory contains no files, it forces re-download by ignoring E-Tag. --- asab/library/providers/libsreg.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/asab/library/providers/libsreg.py b/asab/library/providers/libsreg.py index 4542004a..4b1245e0 100644 --- a/asab/library/providers/libsreg.py +++ b/asab/library/providers/libsreg.py @@ -110,9 +110,15 @@ async def _periodic_pull(self, event_name): # Check for existing E-Tag etag_fname = os.path.join(self.RootPath, "etag") if os.path.exists(etag_fname): - with open(etag_fname, 'r') as f: - etag = f.read().strip() - headers['If-None-Match'] = etag + + # Count number of files in self.RootPath recursively + file_count = sum([len(files) for _, _, files in os.walk(self.RootPath)]) + + # If less than 5 files, we ignore the E-Tag and re-download everything + if file_count > 5: + with open(etag_fname, 'r') as f: + etag = f.read().strip() + headers['If-None-Match'] = etag # Prepare a list of URLs to try # Randomize the order of the URLs (there might be more than one server to try)