From e0d69f6ffb20dafd8b0f367fbf06d0eb8f20788f Mon Sep 17 00:00:00 2001 From: "Vladislav A. Proskurov" Date: Sat, 23 Aug 2025 18:08:49 +0400 Subject: [PATCH 1/2] Fix: skip an entity that is the current directory --- s3fs/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/s3fs/core.py b/s3fs/core.py index 6b80ad89..3263ac98 100644 --- a/s3fs/core.py +++ b/s3fs/core.py @@ -813,6 +813,8 @@ async def _iterdir( self._fill_info(c, bucket, versions=False) yield c for c in i.get(contents_key, []): + if c["Size"] == 0 and c["Key"] == i["Prefix"]: + continue # skip an entity that is the current directory if not self.version_aware or c.get("IsLatest") or versions: c["type"] = "file" c["size"] = c["Size"] From cf3679db90190ae6ecfbabb578c87933dd09fb82 Mon Sep 17 00:00:00 2001 From: "Vladislav A. Proskurov" Date: Sat, 23 Aug 2025 18:15:37 +0400 Subject: [PATCH 2/2] Perf: get empty prefix if not presented --- s3fs/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s3fs/core.py b/s3fs/core.py index 3263ac98..6b02da83 100644 --- a/s3fs/core.py +++ b/s3fs/core.py @@ -813,7 +813,7 @@ async def _iterdir( self._fill_info(c, bucket, versions=False) yield c for c in i.get(contents_key, []): - if c["Size"] == 0 and c["Key"] == i["Prefix"]: + if c["Size"] == 0 and c["Key"] == i.get("Prefix", ""): continue # skip an entity that is the current directory if not self.version_aware or c.get("IsLatest") or versions: c["type"] = "file"