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)
def pack_rel_path(rel_path: str) -> None: pack_path(rel_path) pack_path(integrity.append_hash_suffix(rel_path)) if self._with_sig: pack_path(signature.append_sig_suffix(rel_path))