@@ -434,7 +434,7 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
434434 client = None ):
435435 """Copy the given blob to the given bucket, optionally with a new name.
436436
437- :type blob: string or :class:`gcloud.storage.blob.Blob`
437+ :type blob: :class:`gcloud.storage.blob.Blob`
438438 :param blob: The blob to be copied.
439439
440440 :type destination_bucket: :class:`gcloud.storage.bucket.Bucket`
@@ -461,6 +461,35 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
461461 new_blob ._set_properties (copy_result )
462462 return new_blob
463463
464+ def rename_blob (self , blob , new_name , client = None ):
465+ """Rename the given blob using copy and delete operations.
466+
467+ Effectively, copies blob to the same bucket with a new name, then
468+ deletes the blob.
469+
470+ .. warning::
471+
472+ This method will first duplicate the data and then delete the
473+ old blob. This means that with very large objects renaming
474+ could be a very (temporarily) costly or a very slow operation.
475+
476+ :type blob: :class:`gcloud.storage.blob.Blob`
477+ :param blob: The blob to be renamed.
478+
479+ :type new_name: string
480+ :param new_name: The new name for this blob.
481+
482+ :type client: :class:`gcloud.storage.client.Client` or ``NoneType``
483+ :param client: Optional. The client to use. If not passed, falls back
484+ to the ``client`` stored on the current bucket.
485+
486+ :rtype: :class:`Blob`
487+ :returns: The newly-renamed blob.
488+ """
489+ new_blob = self .copy_blob (blob , self , new_name , client = client )
490+ blob .delete (client = client )
491+ return new_blob
492+
464493 @property
465494 def cors (self ):
466495 """Retrieve CORS policies configured for this bucket.
0 commit comments