Beispiel #1
0
    def _finalize_blob_storage(self, app_config):
        """ When an upload is successful, this ends the uploading process from the storage's perspective.

            Returns True if the blob already existed. """
        computed_digest = digest_tools.sha256_digest_from_hashlib(
            self.blob_upload.sha_state)
        final_blob_location = digest_tools.content_path(computed_digest)

        # Close the database connection before we perform this operation, as it can take a while
        # and we shouldn't hold the connection during that time.
        with CloseForLongOperation(app_config):
            # Move the storage into place, or if this was a re-upload, cancel it
            already_existed = self.storage.exists(
                {self.blob_upload.location_name}, final_blob_location)
            if already_existed:
                # It already existed, clean up our upload which served as proof that the
                # uploader had the blob.
                self.storage.cancel_chunked_upload(
                    {self.blob_upload.location_name},
                    self.blob_upload.upload_id,
                    self.blob_upload.storage_metadata,
                )
            else:
                # We were the first ones to upload this image (at least to this location)
                # Let's copy it into place
                self.storage.complete_chunked_upload(
                    {self.blob_upload.location_name},
                    self.blob_upload.upload_id,
                    final_blob_location,
                    self.blob_upload.storage_metadata,
                )

        return already_existed
Beispiel #2
0
 def blob_path(self, digest_str):
     return content_path(digest_str)
Beispiel #3
0
def test_paths(digest, path):
    assert content_path(digest) == path