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

Added blob exists method #13221

Merged
merged 12 commits into from
Sep 4, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ def undelete_blob(self, **kwargs):
process_storage_error(error)

@distributed_trace()
def exists(self, timeout=None, version_id=None):
def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a blob exists with the defined parameters, and returns
Expand All @@ -933,10 +933,14 @@ def exists(self, timeout=None, version_id=None):
:returns: boolean
"""
try:
self._client.blob.get_properties(
timeout=timeout,
version_id=version_id)
return True
blob_props = self._client.blob.get_properties(
timeout=kwargs.pop('timeout', None),
version_id=kwargs.pop('version_id', None),
tasherif-msft marked this conversation as resolved.
Show resolved Hide resolved
snapshot=self.snapshot,
cls=deserialize_blob_properties)
if blob_props and blob_props.is_current_version or blob_props and self.snapshot:
tasherif-msft marked this conversation as resolved.
Show resolved Hide resolved
tasherif-msft marked this conversation as resolved.
Show resolved Hide resolved
return True
return False
except StorageErrorException:
tasherif-msft marked this conversation as resolved.
Show resolved Hide resolved
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,32 @@ async def undelete_blob(self, **kwargs):
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace_async
async def exists(self, **kwargs):
# type: (**Any) -> bool
"""
Returns True if a blob exists with the defined parameters, and returns
False otherwise.

:param str version_id:
The version id parameter is an opaque DateTime
value that, when present, specifies the version of the blob to check if it exists.
:param int timeout:
The timeout parameter is expressed in seconds.
:returns: boolean
"""
try:
blob_props = await self._client.blob.get_properties(
timeout=kwargs.pop('timeout', None),
version_id=kwargs.pop('version_id', None),
snapshot=self.snapshot,
cls=deserialize_blob_properties)
if blob_props and blob_props.is_current_version or blob_props and self.snapshot:
return True
return False
except StorageErrorException:
return False
tasherif-msft marked this conversation as resolved.
Show resolved Hide resolved

@distributed_trace_async
async def get_blob_properties(self, **kwargs):
# type: (Any) -> BlobProperties
Expand Down
Loading