Ejemplo n.º 1
0
 def verify(self, path: Path, *, with_sig: bool = False) -> None:
     """
     Raises:
         MissingFileError - path or associated sha256path doesn't exist
         IntegrityError - paths exists with bad hash
     """
     hash_path = integrity.path_append_hash_suffix(path)
     common.vprint("[verify] {}".format(path))
     integrity.verify(path, hash_path)
     if with_sig:
         sig_path = signature.path_append_sig_suffix(path)
         self.sig_verify(path, sig_path)
Ejemplo n.º 2
0
    def download_verify(self,
                        dest_url: str,
                        dest_path: Path,
                        *,
                        cached: bool = True,
                        assume_ok: bool = False,
                        with_sig: bool = False) -> None:
        hash_path = integrity.path_append_hash_suffix(dest_path)
        sig_path = signature.path_append_sig_suffix(dest_path)
        if cached:
            if (assume_ok and dest_path.is_file() and hash_path.is_file()
                    and (not with_sig or sig_path.is_file())):
                common.vvprint("[assuming OK] {}".format(dest_path))
                return
            try:
                integrity.verify(dest_path, hash_path)
                if with_sig:
                    self.sig_verify(dest_path, sig_path)
                common.vprint("[cached file] {}".format(dest_path))
                return
            except (error.MissingFileError, error.IntegrityError):
                pass
        common.vprint("[downloading] {}".format(dest_path))
        # Download the (small) hash and signature files first.
        hash_url = integrity.append_hash_suffix(dest_url)
        self.download(hash_url, hash_path)
        if with_sig:
            sig_url = signature.append_sig_suffix(dest_url)
            self.download(sig_url, sig_path)

        # If dest_path exists and has the correct hash, bypass the downloading
        # step to save download time.
        download_required = True
        if dest_path.is_file():
            try:
                integrity.verify(dest_path, hash_path)
                download_required = False
            except (error.MissingFileError, error.IntegrityError):
                pass
        if download_required:
            self.download(dest_url, dest_path)
            integrity.verify(dest_path, hash_path)

        if with_sig:
            self.sig_verify(dest_path, sig_path)