Skip to content

Commit 8e85462

Browse files
committed
Switch preserve_acl default to True.
1 parent e8149da commit 8e85462

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

google/cloud/storage/bucket.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def delete_blobs(self, blobs, on_error=None, client=None):
440440
raise
441441

442442
def copy_blob(self, blob, destination_bucket, new_name=None,
443-
client=None, preserve_acl=False):
443+
client=None, preserve_acl=True):
444444
"""Copy the given blob to the given bucket, optionally with a new name.
445445
446446
:type blob: :class:`google.cloud.storage.blob.Blob`
@@ -460,7 +460,7 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
460460
461461
:type preserve_acl: bool
462462
:param preserve_acl: Optional. Copies ACL from old blob to new blob.
463-
Default: False.
463+
Default: True.
464464
465465
:rtype: :class:`google.cloud.storage.blob.Blob`
466466
:returns: The new Blob.
@@ -470,14 +470,15 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
470470
new_name = blob.name
471471
new_blob = Blob(bucket=destination_bucket, name=new_name)
472472
api_path = blob.path + '/copyTo' + new_blob.path
473+
if not preserve_acl:
474+
new_blob.acl.reset()
475+
new_blob.acl.save()
473476
copy_result = client.connection.api_request(
474477
method='POST', path=api_path, _target_object=new_blob)
475478
new_blob._set_properties(copy_result)
476-
if preserve_acl:
477-
new_blob.acl.save(blob.acl)
478479
return new_blob
479480

480-
def rename_blob(self, blob, new_name, client=None, preserve_acl=False):
481+
def rename_blob(self, blob, new_name, client=None):
481482
"""Rename the given blob using copy and delete operations.
482483
483484
Effectively, copies blob to the same bucket with a new name, then
@@ -500,15 +501,10 @@ def rename_blob(self, blob, new_name, client=None, preserve_acl=False):
500501
:param client: Optional. The client to use. If not passed, falls back
501502
to the ``client`` stored on the current bucket.
502503
503-
:type preserve_acl: bool
504-
:param preserve_acl: Optional. Copies ACL from old blob to renamed
505-
blob. Default: False.
506-
507504
:rtype: :class:`Blob`
508505
:returns: The newly-renamed blob.
509506
"""
510-
new_blob = self.copy_blob(blob, self, new_name, client=client,
511-
preserve_acl=preserve_acl)
507+
new_blob = self.copy_blob(blob, self, new_name, client=client)
512508
blob.delete(client=client)
513509
return new_blob
514510

unit_tests/storage/test_bucket.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def test_copy_blobs_preserve_acl(self):
543543
BLOB_NAME = 'blob-name'
544544
NEW_NAME = 'new_name'
545545

546-
def save(self, client): # pylint: disable=unused-argument
546+
def save(self): # pylint: disable=unused-argument
547547
return
548548

549549
class _Blob(object):
@@ -552,6 +552,8 @@ class _Blob(object):
552552

553553
def __init__(self):
554554
self.acl = ACL()
555+
self.acl.loaded = True
556+
self.acl.entity('type', 'id')
555557

556558
connection = _Connection({})
557559
client = _Client(connection)
@@ -560,10 +562,12 @@ def __init__(self):
560562
blob = _Blob()
561563
with _Monkey(ACL, save=save):
562564
new_blob = source.copy_blob(blob, dest, NEW_NAME, client=client,
563-
preserve_acl=True)
565+
preserve_acl=False)
564566
self.assertIs(new_blob.bucket, dest)
565567
self.assertEqual(new_blob.name, NEW_NAME)
566568
self.assertIsInstance(new_blob.acl, ObjectACL)
569+
self.assertFalse(new_blob.acl.loaded)
570+
self.assertEqual(new_blob.acl.entities, {})
567571

568572
def test_copy_blobs_w_name(self):
569573
SOURCE = 'source'

0 commit comments

Comments
 (0)