Beispiel #1
0
    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
Beispiel #2
0
 def test_stamp1(self):
     RefreshLog.update(self.ci, DIGEST_DUMMY)  # Must not raise an exception
     self.assertTrue(True)
Beispiel #3
0
 def test_stamp2(self):
     RefreshLog.update(ID2, 'XXX')  # Must not raise an exception
     self.assertTrue(True)