Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make prefix not being recognised as dirs anymore #244

Merged
merged 4 commits into from Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
@@ -1,5 +1,9 @@
# cloudpathlib Changelog

## v0.9.1 (UNRELEASED)

- Fixed S3Path.exists() returns True on partial matches. ([Issue #208](https://github.com/drivendataorg/cloudpathlib/issues/208), [PR #244](https://github.com/drivendataorg/cloudpathlib/pull/244))

## v0.9.0 (2022-06-03)
- Added `absolute` to `CloudPath` (does nothing as `CloudPath` is always absolute) ([PR #230](https://github.com/drivendataorg/cloudpathlib/pull/230))
- Added `resolve` to `CloudPath` (does nothing as `CloudPath` is resolved in advance) ([Issue #151](https://github.com/drivendataorg/cloudpathlib/issues/151), [PR #230](https://github.com/drivendataorg/cloudpathlib/pull/230))
Expand Down
6 changes: 3 additions & 3 deletions cloudpathlib/s3/s3client.py
Expand Up @@ -156,13 +156,13 @@ def _s3_file_query(self, cloud_path: S3Path):

# else, confirm it is a dir by filtering to the first item under the prefix
except ClientError:
key = cloud_path.key.rstrip("/") + "/"

return next(
(
obj
for obj in (
self.s3.Bucket(cloud_path.bucket)
.objects.filter(Prefix=cloud_path.key)
.limit(1)
self.s3.Bucket(cloud_path.bucket).objects.filter(Prefix=key).limit(1)
)
),
None,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_s3_specific.py
Expand Up @@ -164,6 +164,24 @@ def test_fake_directories(s3_like_rig):
assert not test_case.is_file()


def test_directories(s3_like_rig):
"""Fixing bug that marks as directories prefixes of existing paths

Ref: https://github.com/drivendataorg/cloudpathlib/issues/208
"""
super_path = s3_like_rig.create_cloud_path("dir_0/file0_0.txt")
assert super_path.exists()
assert not super_path.is_dir()

super_path = s3_like_rig.create_cloud_path("dir_0")
assert super_path.exists()
assert super_path.is_dir()

super_path = s3_like_rig.create_cloud_path("dir_0/file0")
assert not super_path.exists()
assert not super_path.is_dir()


def test_no_sign_request(s3_rig, tmp_path):
"""Tests that we can pass no_sign_request to the S3Client and we will
be able to access public resources but not private ones.
Expand Down