Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion sdk/storage/azure_storage_blob/assets.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "rust",
"Tag": "rust/azure_storage_blob_f9b39b45b4",
"Tag": "rust/azure_storage_blob_fc6c153d44",
"TagPrefix": "rust/azure_storage_blob"
}
25 changes: 23 additions & 2 deletions sdk/storage/azure_storage_blob/src/clients/blob_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ use crate::{
BlobClientReleaseLeaseOptions, BlobClientRenewLeaseOptions, BlobClientSetMetadataOptions,
BlobClientSetPropertiesOptions, BlobClientSetTagsOptions, BlobClientSetTierOptions,
BlobTags, BlockBlobClientCommitBlockListOptions, BlockBlobClientUploadOptions, BlockList,
BlockListType, BlockLookupList,
BlockListType, BlockLookupList, StorageErrorCode,
},
pipeline::StorageHeadersPolicy,
AppendBlobClient, BlobClientOptions, BlockBlobClient, PageBlobClient,
};
use azure_core::{
credentials::TokenCredential,
error::ErrorKind,
http::{
policies::{BearerTokenCredentialPolicy, Policy},
JsonFormat, NoFormat, RequestContent, Response, Url, XmlFormat,
JsonFormat, NoFormat, RequestContent, Response, StatusCode, Url, XmlFormat,
},
Bytes, Result,
};
Expand Down Expand Up @@ -355,4 +356,24 @@ impl BlobClient {
) -> Result<Response<BlobClientGetAccountInfoResult, NoFormat>> {
self.client.get_account_info(options).await
}

/// Returns `true` if the blob exists, `false` if the blob does not exist, and propagates all other errors.
pub async fn exists(&self) -> Result<bool> {
match self.client.get_properties(None).await {
Ok(_) => Ok(true),
Err(e) if e.http_status() == Some(StatusCode::NotFound) => match e.kind() {
ErrorKind::HttpResponse {
error_code: Some(error_code),
..
} if error_code == StorageErrorCode::BlobNotFound.as_ref()
|| error_code == StorageErrorCode::ContainerNotFound.as_ref() =>
{
Ok(false)
}
// Propagate all other error types.
_ => Err(e),
},
Err(e) => Err(e),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ use crate::{
BlobContainerClientGetAccountInfoOptions, BlobContainerClientGetPropertiesOptions,
BlobContainerClientListBlobFlatSegmentOptions, BlobContainerClientReleaseLeaseOptions,
BlobContainerClientRenewLeaseOptions, BlobContainerClientSetMetadataOptions,
FilterBlobSegment, ListBlobsFlatSegmentResponse,
FilterBlobSegment, ListBlobsFlatSegmentResponse, StorageErrorCode,
},
pipeline::StorageHeadersPolicy,
BlobClient, BlobContainerClientOptions,
};
use azure_core::{
credentials::TokenCredential,
error::ErrorKind,
http::{
policies::{BearerTokenCredentialPolicy, Policy},
NoFormat, PageIterator, Pager, Response, Url, XmlFormat,
NoFormat, PageIterator, Pager, Response, StatusCode, Url, XmlFormat,
},
Result,
};
Expand Down Expand Up @@ -275,4 +276,20 @@ impl BlobContainerClient {
) -> Result<Response<BlobContainerClientGetAccountInfoResult, NoFormat>> {
self.client.get_account_info(options).await
}

/// Returns `true` if the container exists, `false` if the container does not exist, and propagates all other errors.
pub async fn exists(&self) -> Result<bool> {
match self.client.get_properties(None).await {
Ok(_) => Ok(true),
Err(e) if e.http_status() == Some(StatusCode::NotFound) => match e.kind() {
ErrorKind::HttpResponse {
error_code: Some(error_code),
..
} if error_code == StorageErrorCode::ContainerNotFound.as_ref() => Ok(false),
// Propagate all other error types.
_ => Err(e),
},
Err(e) => Err(e),
}
}
}
Loading