Beispiel #1
0
 def _write_manifest(self, manifest: Manifest, date: str,
                     channel: str) -> None:
     src_path = self.manifest_path(manifest.date, manifest.channel)
     dst_path = self.manifest_path(date, channel)
     common.iprint("[publish] {}".format(dst_path))
     shutil.copyfile(str(src_path), str(dst_path))
     src_hash_path = integrity.path_append_hash_suffix(src_path)
     dst_hash_path = integrity.path_append_hash_suffix(dst_path)
     shutil.copyfile(str(src_hash_path), str(dst_hash_path))
     src_sig_path = signature.path_append_sig_suffix(src_path)
     dst_sig_path = signature.path_append_sig_suffix(dst_path)
     shutil.copyfile(str(src_sig_path), str(dst_sig_path))
Beispiel #2
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)
Beispiel #3
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)