Skip to content

Commit

Permalink
fix(az): correctly identify files and directories
Browse files Browse the repository at this point in the history
  • Loading branch information
M0dEx committed Jul 3, 2024
1 parent ee24ee6 commit 1251480
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cloudpathlib/azure/azblobclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import mimetypes
import os
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, Optional, Tuple, Union

from typing import Any, Callable, Dict, Iterable, Optional, Tuple, Union, cast

from ..client import Client, register_client_class
from ..cloudpath import implementation_registry
Expand Down Expand Up @@ -156,7 +155,20 @@ def _is_file_or_dir(self, cloud_path: AzureBlobPath) -> Optional[str]:
return "dir"

try:
self._get_metadata(cloud_path)
# the result of get_blob_properties is a BlobProperties object (dict mixin)
metadata = cast(BlobProperties, self._get_metadata(cloud_path))

# content_type and content_md5 are never None for files in Azure Blob Storage
# if they are None, then the given path is a directory
# https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-properties?tabs=microsoft-entra-id#response-headers
is_folder = (
metadata.content_settings.content_type is None
and metadata.content_settings.content_md5 is None
)

if is_folder:
return "dir"

return "file"
except ResourceNotFoundError:
prefix = cloud_path.blob
Expand Down

0 comments on commit 1251480

Please sign in to comment.