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

spec: support exists() on directories pre-cache #237

Merged
merged 8 commits into from
Jun 8, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
**Change Log**
v0.7.5
------
- `exists()` calls now also checks whether a directory with that name exists or not. Previously this was only checked from the cache.

v0.7.4
------
- Added the location_mode parameter to AzureBlobFileSystem object, and set default to "primary" to enable Access Control Lists and RA-GRS access. Valid values are "primary" and "secondary"
Expand Down
15 changes: 13 additions & 2 deletions adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,19 @@ async def _exists(self, path):
return True

async with self.service_client.get_blob_client(container_name, path) as bc:
exists = await bc.exists()
return exists
if await bc.exists():
return True

dir_path = path.rstrip("/") + "/"
async with self.service_client.get_container_client(
container=container_name
) as container_client:
async for blob in container_client.list_blobs(
results_per_page=1, name_starts_with=dir_path
):
return True
else:
return False

async def _pipe_file(self, path, value, overwrite=True, **kwargs):
"""Set the bytes of given file"""
Expand Down
19 changes: 18 additions & 1 deletion adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,11 +1244,28 @@ def test_exists(storage):
assert not fs.exists("data/not-a-key")


def test_find_with_prefix(storage):
def test_exists_directory(storage):
fs = AzureBlobFileSystem(
account_name=storage.account_name, connection_string=CONN_STR
)

fs.mkdir("temp_exists")
fs.touch("temp_exists/data/data.txt")
fs.touch("temp_exists/data/something/data.txt")
fs.invalidate_cache()

assert fs.exists("temp_exists/data/something/")
assert fs.exists("temp_exists/data/something")
assert fs.exists("temp_exists/data/")
assert fs.exists("temp_exists/data")
assert fs.exists("temp_exists/")
assert fs.exists("temp_exists")


def test_find_with_prefix(storage):
fs = AzureBlobFileSystem(
account_name=storage.account_name, connection_string=CONN_STR
)
test_bucket_name = "data"

for cursor in range(25):
Expand Down