Skip to content

Commit 17f6e56

Browse files
authored
[s3] Fix directory check in S3FileSystem by appending '/' to prefix (#4261)
1 parent 85b8202 commit 17f6e56

File tree

1 file changed

+3
-1
lines changed
  • desktop/core/src/desktop/lib/fs/s3/core

1 file changed

+3
-1
lines changed

desktop/core/src/desktop/lib/fs/s3/core/s3fs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def stats(self, path: Union[str, S3Path]) -> S3Stat:
213213
except FileNotFoundError:
214214
# Check if it's a prefix (directory)
215215
try:
216-
response = self.s3_client.list_objects_v2(Bucket=path.bucket, Prefix=path.key, Delimiter=S3_DELIMITER, MaxKeys=1)
216+
# For directory check, append '/' to avoid matching files that start with same prefix
217+
directory_prefix = path.key.rstrip("/") + "/"
218+
response = self.s3_client.list_objects_v2(Bucket=path.bucket, Prefix=directory_prefix, Delimiter=S3_DELIMITER, MaxKeys=1)
217219
if response.get("CommonPrefixes") or response.get("Contents"):
218220
return S3Stat.for_directory(path)
219221
raise FileNotFoundError(f"Path not found: {path}")

0 commit comments

Comments
 (0)