Skip to content

Commit 2ccadeb

Browse files
If no key get bucket info (#987)
1 parent 78a535f commit 2ccadeb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

s3fs/core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,18 @@ async def _info(self, path, bucket=None, key=None, refresh=False, version_id=Non
14641464
pass
14651465
except ClientError as e:
14661466
raise translate_boto_error(e, set_cause=False)
1467+
else:
1468+
try:
1469+
out = await self._call_s3("head_bucket", Bucket=bucket, **self.req_kw)
1470+
return {
1471+
"name": bucket,
1472+
"type": "directory",
1473+
"size": 0,
1474+
"StorageClass": "DIRECTORY",
1475+
"VersionId": out.get("VersionId"),
1476+
}
1477+
except ClientError as e:
1478+
raise translate_boto_error(e, set_cause=False)
14671479

14681480
try:
14691481
# We check to see if the path is a directory by attempting to list its

s3fs/tests/test_s3fs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,3 +2986,10 @@ def test_put_exclusive_small(s3, tmpdir):
29862986
with pytest.raises(FileExistsError):
29872987
s3.put(fn, f"{test_bucket_name}/afile", mode="create")
29882988
assert not s3.list_multipart_uploads(test_bucket_name)
2989+
2990+
2991+
def test_bucket_info(s3):
2992+
info = s3.info(test_bucket_name)
2993+
assert "VersionId" in info
2994+
assert info["type"] == "directory"
2995+
assert info["name"] == test_bucket_name

0 commit comments

Comments
 (0)