Beispiel #1
0
    def check_integrity(self, digest: str,
                        download_action: DownloadAction) -> None:
        """
        Check the integrity of a downloaded chunked file.
        Update the progress of the verification during the computation of the digest.
        """
        digester = get_digest_algorithm(digest)
        filepath = download_action.tmppath or download_action.filepath

        # Terminate the download action to be able to start the verification one as we are allowing
        # only 1 action per thread.
        # Note that this is not really needed as the verification action would replace the download
        # one, but let's do things right.
        DownloadAction.finish_action()

        verif_action = VerificationAction(filepath,
                                          reporter=QApplication.instance())

        def callback(_):
            verif_action.progress += FILE_BUFFER_SIZE

        try:
            computed_digest = compute_digest(filepath,
                                             digester,
                                             callback=callback)
            if digest != computed_digest:
                # TMP file and Downloads table entry will be deleted
                # by the calling method
                raise CorruptedFile(filepath, digest, computed_digest)
        finally:
            VerificationAction.finish_action()
    def check_integrity(self, digest: str,
                        download_action: DownloadAction) -> None:
        """
        Check the integrity of a downloaded chunked file.
        Update the progress of the verification during the computation of the digest.
        """
        if Options.disabled_file_integrity_check:
            log.debug(
                "disabled_file_integrity_check is True, skipping file integrity check then"
            )
            return

        digester = get_digest_algorithm(digest)
        if not digester:
            log.warning(
                f"Empty or non-standard digest {digest!r}, skipping the file integrity check"
            )
            return

        size = download_action.size
        filepath = download_action.tmppath or download_action.filepath

        # Terminate the download action to be able to start the verification one as we are allowing
        # only 1 action per thread.
        # Note that this is not really needed as the verification action would replace the download
        # one, but let's do things right.
        DownloadAction.finish_action()

        verif_action = VerificationAction(filepath,
                                          size,
                                          reporter=QApplication.instance())

        def callback(_: Path) -> None:
            verif_action.progress += FILE_BUFFER_SIZE

        try:
            computed_digest = compute_digest(filepath,
                                             digester,
                                             callback=callback)
            if digest != computed_digest:
                # TMP file and Downloads table entry will be deleted
                # by the calling method
                raise CorruptedFile(filepath, digest, computed_digest)
        finally:
            VerificationAction.finish_action()
    def check_integrity_simple(self, digest: str, file: Path) -> None:
        """Check the integrity of a relatively small downloaded file."""
        if Options.disabled_file_integrity_check:
            log.debug(
                "disabled_file_integrity_check is True, skipping file integrity check then"
            )
            return

        digester = get_digest_algorithm(digest)
        if not digester:
            log.warning(
                f"Empty or non-standard digest {digest!r}, skipping the file integrity check"
            )
            return

        computed_digest = compute_digest(file, digester)
        if digest != computed_digest:
            raise CorruptedFile(file, digest, computed_digest)
Beispiel #4
0
 def corrupted_download(*args, **__):
     file_out = args[2]
     file_out.write_bytes(b"test")
     raise CorruptedFile("Mock'ed test", "remote-digest", "local-digest")
Beispiel #5
0
 def check_integrity_simple(self, digest: str, file: Path) -> None:
     """Check the integrity of a relatively small downloaded file."""
     digester = get_digest_algorithm(digest)
     computed_digest = compute_digest(file, digester)
     if digest != computed_digest:
         raise CorruptedFile(file, digest, computed_digest)
Beispiel #6
0
 def corrupted_download(*_, **__):
     raise CorruptedFile("Mock'ed test", "remote-digest", "local-digest")