diff --git a/CHANGELOG.md b/CHANGELOG.md index df4ad3b5..6038b766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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" diff --git a/adlfs/spec.py b/adlfs/spec.py index 25fa5ccc..6055f082 100644 --- a/adlfs/spec.py +++ b/adlfs/spec.py @@ -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""" diff --git a/adlfs/tests/test_spec.py b/adlfs/tests/test_spec.py index cc6268c3..c1db7654 100644 --- a/adlfs/tests/test_spec.py +++ b/adlfs/tests/test_spec.py @@ -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):