Skip to content

Commit

Permalink
Add recursive= to chmod (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Jan 4, 2023
1 parent 804057f commit 59f9839
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ async def _setxattr(self, path, copy_kwargs=None, **kw_args):

setxattr = sync_wrapper(_setxattr)

async def _chmod(self, path, acl, **kwargs):
async def _chmod(self, path, acl, recursive=False, **kwargs):
"""Set Access Control on a bucket/key
See http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
Expand All @@ -1538,9 +1538,14 @@ async def _chmod(self, path, acl, **kwargs):
the object to set
acl : string
the value of ACL to apply
recursive : bool
whether to apply the ACL to all keys below the given path too
"""
bucket, key, version_id = self.split_path(path)
if key:
if recursive:
allfiles = await self._find(path, withdirs=False)
await asyncio.gather(*[self._chmod(p, recursive=False) for p in allfiles])
elif key:
if acl not in key_acls:
raise ValueError("ACL not in %s", key_acls)
await self._call_s3(
Expand All @@ -1551,7 +1556,7 @@ async def _chmod(self, path, acl, **kwargs):
ACL=acl,
**version_id_kw(version_id),
)
else:
if not key:
if acl not in buck_acls:
raise ValueError("ACL not in %s", buck_acls)
await self._call_s3("put_bucket_acl", kwargs, Bucket=bucket, ACL=acl)
Expand Down

0 comments on commit 59f9839

Please sign in to comment.