Skip to content

Commit 59f9839

Browse files
authored
Add recursive= to chmod (#679)
1 parent 804057f commit 59f9839

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎s3fs/core.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ async def _setxattr(self, path, copy_kwargs=None, **kw_args):
15271527

15281528
setxattr = sync_wrapper(_setxattr)
15291529

1530-
async def _chmod(self, path, acl, **kwargs):
1530+
async def _chmod(self, path, acl, recursive=False, **kwargs):
15311531
"""Set Access Control on a bucket/key
15321532
15331533
See http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
@@ -1538,9 +1538,14 @@ async def _chmod(self, path, acl, **kwargs):
15381538
the object to set
15391539
acl : string
15401540
the value of ACL to apply
1541+
recursive : bool
1542+
whether to apply the ACL to all keys below the given path too
15411543
"""
15421544
bucket, key, version_id = self.split_path(path)
1543-
if key:
1545+
if recursive:
1546+
allfiles = await self._find(path, withdirs=False)
1547+
await asyncio.gather(*[self._chmod(p, recursive=False) for p in allfiles])
1548+
elif key:
15441549
if acl not in key_acls:
15451550
raise ValueError("ACL not in %s", key_acls)
15461551
await self._call_s3(
@@ -1551,7 +1556,7 @@ async def _chmod(self, path, acl, **kwargs):
15511556
ACL=acl,
15521557
**version_id_kw(version_id),
15531558
)
1554-
else:
1559+
if not key:
15551560
if acl not in buck_acls:
15561561
raise ValueError("ACL not in %s", buck_acls)
15571562
await self._call_s3("put_bucket_acl", kwargs, Bucket=bucket, ACL=acl)

0 commit comments

Comments
 (0)