Пример #1
0
    def _download_verify(self, download: bool, specs: List[str],
                         base_targets: List[str]) -> None:
        for spec in specs:
            common.iprint("{}: {}".format("Download" if download else "Verify",
                                          spec))
            manifest = self.select_manifest(spec,
                                            download=download,
                                            canonical=True)
            common.iprint("  ident: {}".format(manifest.ident))

            targets = self.adjust_targets(manifest, base_targets)
            packages = list(manifest.gen_available_packages(targets=targets))
            common.iprint("  packages: {}, targets: {}".format(
                len(packages), len(targets)))
            for t in targets:
                common.vvprint("  target: {}".format(t))

            for package in packages:
                rel_path = package.rel_path
                dest_path = self.dest_path_from_rel_path(rel_path)
                dest_url = self.url_from_rel_path(rel_path)
                if download:
                    self.downloader.download_verify(
                        dest_url,
                        dest_path,
                        assume_ok=self.args.assume_ok,
                        with_sig=self._with_sig,
                    )
                else:
                    self.downloader.verify(dest_path, with_sig=self._with_sig)
Пример #2
0
    def cmd_pack(self) -> None:
        base_targets = dist.require_targets(self.targets, default="*")
        archive_path = self.get_archive_path()
        common.iprint("Packing archive: {}".format(archive_path))
        with common.tar_context(archive_path, "w") as tar_f:

            def pack_path(rel_path: str) -> None:
                dest_path = self.dest_path_from_rel_path(rel_path)
                packed_name = "rustup/" + rel_path
                common.vprint("[pack] {}".format(rel_path))
                try:
                    tar_f.add(str(dest_path), packed_name)
                except FileNotFoundError:
                    raise error.MissingFileError(str(dest_path))

            def pack_rel_path(rel_path: str) -> None:
                pack_path(rel_path)
                pack_path(integrity.append_hash_suffix(rel_path))

            for spec in self.adjust_wild_specs(self.specs):
                common.iprint("Pack: {}".format(spec))
                version = self.version_from_spec(spec, download=False)
                common.iprint("  version: {}".format(version))

                targets = self.adjust_targets(version, base_targets)
                common.iprint("  targets: {}".format(len(targets)))
                for t in targets:
                    common.vvprint("  target: {}".format(t))

                for target in targets:
                    rel_path = self.rustup_init_rel_path(version, target)
                    pack_rel_path(rel_path)
Пример #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)
Пример #4
0
    def cmd_pack(self) -> None:
        base_targets = dist.require_targets(self.targets, default="*")
        archive_path = self.get_archive_path()
        common.iprint("Packing archive: {}".format(archive_path))
        with common.tar_context(archive_path, "w") as tar_f:

            def pack_path(rel_path: str) -> None:
                dest_path = self.dest_path_from_rel_path(rel_path)
                packed_name = "dist/" + rel_path
                common.vprint("[pack] {}".format(rel_path))
                try:
                    tar_f.add(str(dest_path), packed_name)
                except FileNotFoundError:
                    raise error.MissingFileError(str(dest_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))

            for spec in self.adjust_wild_specs(self.specs):
                common.iprint("Pack: {}".format(spec))
                manifest = self.select_manifest(spec,
                                                download=False,
                                                canonical=True)
                common.iprint("  ident: {}".format(manifest.ident))

                targets = self.adjust_targets(manifest, base_targets)
                packages = list(
                    manifest.gen_available_packages(targets=targets))
                common.iprint("  packages: {}, targets: {}".format(
                    len(packages), len(targets)))
                for t in targets:
                    common.vvprint("  target: {}".format(t))

                # Pack channel file.
                pack_rel_path(channel_rel_path(manifest.date,
                                               manifest.channel))

                # Pack up package file parts.
                for package in packages:
                    pack_rel_path(package.rel_path)
Пример #5
0
 def download_verify_hash(self,
                          dest_url: str,
                          dest_path: Path,
                          hash: str,
                          *,
                          cached: bool = True,
                          assume_ok: bool = False) -> None:
     if cached:
         if assume_ok and dest_path.is_file():
             common.vvprint("[assuming OK] {}".format(dest_path))
             return
         try:
             integrity.verify_hash(dest_path, hash)
             common.vprint("[cached file] {}".format(dest_path))
             return
         except (error.MissingFileError, error.IntegrityError):
             pass
     common.vprint("[downloading] {}".format(dest_path))
     self.download(dest_url, dest_path)
     integrity.verify_hash(dest_path, hash)
Пример #6
0
    def _download_verify(self, download: bool, specs: List[str],
                         base_targets: List[str]) -> None:
        for spec in specs:
            common.iprint("{}: {}".format("Download" if download else "Verify",
                                          spec))
            version = self.version_from_spec(spec, download=download)
            common.iprint("  version: {}".format(version))

            targets = self.adjust_targets(version, base_targets)
            common.iprint("  targets: {}".format(len(targets)))
            for t in targets:
                common.vvprint("  target: {}".format(t))

            for target in targets:
                rel_path = self.rustup_init_rel_path(version, target)
                dest_path = self.dest_path_from_rel_path(rel_path)
                dest_url = self.url_from_rel_path(rel_path)
                if download:
                    self.downloader.download_verify(
                        dest_url, dest_path, assume_ok=self.args.assume_ok)
                else:
                    self.downloader.verify(dest_path)
Пример #7
0
def write_hash_file_for(path: Path) -> None:
    h = hash_file(path)
    path_sha256 = path_append_hash_suffix(path)
    common.vvprint("[{}] writing hash file".format(path))
    with path_sha256.open("w") as f:
        f.write("{}  {}\n".format(h, path.name))