Exemplo n.º 1
0
 def is_blob_verified(self, blob_hash: str, length: typing.Optional[int] = None) -> bool:
     if not is_valid_blobhash(blob_hash):
         raise ValueError(blob_hash)
     if not os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
         return False
     if blob_hash in self.blobs:
         return self.blobs[blob_hash].get_is_verified()
     return self._get_blob(blob_hash, length).get_is_verified()
Exemplo n.º 2
0
 def get_files_in_blob_dir() -> typing.Set[str]:
     if not self.blob_dir:
         return set()
     return {
         item.name
         for item in os.scandir(self.blob_dir)
         if is_valid_blobhash(item.name)
     }
Exemplo n.º 3
0
 def _get_blob(self, blob_hash: str, length: typing.Optional[int] = None):
     if self.config.save_blobs or (
             is_valid_blobhash(blob_hash)
             and os.path.isfile(os.path.join(self.blob_dir, blob_hash))):
         return BlobFile(self.loop, blob_hash, length, self.blob_completed,
                         self.blob_dir)
     return BlobBuffer(self.loop, blob_hash, length, self.blob_completed,
                       self.blob_dir)
Exemplo n.º 4
0
    def delete_blob(self, blob_hash: str):
        if not is_valid_blobhash(blob_hash):
            raise Exception("invalid blob hash to delete")

        if blob_hash not in self.blobs:
            if self.blob_dir and os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
                os.remove(os.path.join(self.blob_dir, blob_hash))
        else:
            self.blobs.pop(blob_hash).delete()
            if blob_hash in self.completed_blob_hashes:
                self.completed_blob_hashes.remove(blob_hash)