def refresh(self, ci: ClamavItem) -> bool: """Refresh a single ClamAV item. :param ci: Item to refresh. :return: True if new payload data was written, False otherwise. """ try: if self.args.force: log.debug(f'{ci.url} refresh forced') elif not RefreshLog.is_outdated(ci.url, ci.interval): log.debug(f'{ci.url} below max age') return False digest = get_digest(ci) if not digest.ok: return False if digest.data and RefreshLog.digest_matches(ci.url, digest.data): log.debug(f'{ci.url} unchanged') RefreshLog.update(ci.url, digest.data) # Update timestamp return False payload = get_payload(ci) if not payload.ok: return False integrity = check_integrity(payload.data, ci.check, digest.data) if not integrity.ok: log.warning(f'{ci.url} {integrity.data}') return False with open(ci.path, 'wb') as f: size = f.write(payload.data) log.info(f'{ci.path} updated ({size} bytes)') RefreshLog.update(ci.url, digest.data) # Update digest and timestamp except OSError as e: # pragma: no cover log.exception(e) return True
def test_refresh_required(self): self.assertTrue(RefreshLog.is_outdated(URL1, 0))