浏览代码

[s3] Fix directory check in S3FileSystem by appending '/' to prefix (#4261)

Harsh Gupta 2 月之前
父节点
当前提交
17f6e56d86
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      desktop/core/src/desktop/lib/fs/s3/core/s3fs.py

+ 3 - 1
desktop/core/src/desktop/lib/fs/s3/core/s3fs.py

@@ -213,7 +213,9 @@ class S3FileSystem:
     except FileNotFoundError:
       # Check if it's a prefix (directory)
       try:
-        response = self.s3_client.list_objects_v2(Bucket=path.bucket, Prefix=path.key, Delimiter=S3_DELIMITER, MaxKeys=1)
+        # For directory check, append '/' to avoid matching files that start with same prefix
+        directory_prefix = path.key.rstrip("/") + "/"
+        response = self.s3_client.list_objects_v2(Bucket=path.bucket, Prefix=directory_prefix, Delimiter=S3_DELIMITER, MaxKeys=1)
         if response.get("CommonPrefixes") or response.get("Contents"):
           return S3Stat.for_directory(path)
         raise FileNotFoundError(f"Path not found: {path}")