Ejemplo n.º 1
0
    def delete_package(self, pkg_name: str, top_hash: str = None):
        package_path = self.pointers_dir(pkg_name)
        paths = list(list_url(package_path))
        if not paths:
            raise QuiltException(
                "No such package exists in the given directory.")

        if top_hash is not None:
            top_hash = self.resolve_top_hash(pkg_name, top_hash)
            deleted = []
            remaining = []
            for path, _ in paths:
                pkg_hash = get_bytes(self.pointer_pk(pkg_name, path)).decode()
                (deleted if pkg_hash == top_hash else remaining).append(path)
            if not deleted:
                raise QuiltException(
                    "No such package version exists in the given directory.")
            for path in deleted:
                delete_url(self.pointer_pk(pkg_name, path))
            if 'latest' in deleted and remaining:
                # Create a new "latest". Technically, we need to compare numerically,
                # but string comparisons will be fine till year 2286.
                new_latest = max(remaining)
                copy_file(self.pointer_pk(pkg_name, new_latest),
                          self.pointer_latest_pk(pkg_name))
        else:
            for path, _ in paths:
                delete_url(self.pointer_pk(pkg_name, path))
Ejemplo n.º 2
0
 def resolve_top_hash(self, pkg_name: str, hash_prefix: str) -> str:
     if len(hash_prefix) == 64:
         top_hash = hash_prefix
     elif 6 <= len(hash_prefix) < 64:
         matching_hashes = [self._top_hash_from_path(h) for h, _
                            in list_url(self.manifests_package_dir(pkg_name))
                            if h.startswith(hash_prefix)]
         if not matching_hashes:
             raise QuiltException("Found zero matches for %r" % hash_prefix)
         elif len(matching_hashes) > 1:
             raise QuiltException("Found multiple matches: %r" % hash_prefix)
         else:
             top_hash = matching_hashes[0]
     else:
         raise QuiltException("Invalid hash: %r" % hash_prefix)
     # TODO: verify that name is correct with respect to this top_hash
     return top_hash
Ejemplo n.º 3
0
 def delete_package_version(self, pkg_name: str, top_hash: str):
     deleted = []
     remaining = []
     for path, pkg_hash in self.list_package_versions(pkg_name):
         (deleted if pkg_hash == top_hash else remaining).append(path)
     if not deleted:
         raise QuiltException("No such package version exists in the given directory.")
     for path in deleted:
         delete_url(self.pointer_pk(pkg_name, path))
     if 'latest' in deleted and remaining:
         # Create a new "latest". Technically, we need to compare numerically,
         # but string comparisons will be fine till year 2286.
         new_latest = max(remaining)
         copy_file(self.pointer_pk(pkg_name, new_latest), self.pointer_latest_pk(pkg_name))