add a bool indicating whether the opration succeeds for CreateIfNotExists/DeleteIfExists (#1313)
This commit is contained in:
parent
91f95dc19d
commit
0643eeba5d
@ -119,8 +119,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
* exists.
|
||||
*
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A CreateAppendBlobResult describing the newly created append blob. Null if the blob
|
||||
* already exists.
|
||||
* @return A CreateAppendBlobResult describing the newly created append blob.
|
||||
* CreateAppendBlobResult.Created is false if the blob already exists.
|
||||
*/
|
||||
Azure::Core::Response<Models::CreateAppendBlobResult> CreateIfNotExists(
|
||||
const CreateAppendBlobOptions& options = CreateAppendBlobOptions()) const;
|
||||
|
||||
@ -278,7 +278,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
* @brief Marks the specified blob or snapshot for deletion if it exists.
|
||||
*
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A DeleteBlobResult on successfully deleting. Null if the blob doesn't exist.
|
||||
* @return A DeleteBlobResult on successfully deleting. DeleteBlobResult.Deleted is false if the
|
||||
* blob doesn't exist.
|
||||
*/
|
||||
Azure::Core::Response<Models::DeleteBlobResult> DeleteIfExists(
|
||||
const DeleteBlobOptions& options = DeleteBlobOptions()) const;
|
||||
|
||||
@ -137,7 +137,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
*
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A CreateBlobContainerResult describing the newly created blob container if the
|
||||
* container doesn't exist. Null if the container already exists.
|
||||
* container doesn't exist. CreateBlobContainerResult.Created is false if the container already
|
||||
* exists.
|
||||
*/
|
||||
Azure::Core::Response<Models::CreateBlobContainerResult> CreateIfNotExists(
|
||||
const CreateBlobContainerOptions& options = CreateBlobContainerOptions()) const;
|
||||
@ -157,8 +158,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
* contained within it are later deleted during garbage collection.
|
||||
*
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A DeleteBlobContainerResult if the container exists. Null if the container doesn't
|
||||
* exist.
|
||||
* @return A DeleteBlobContainerResult if the container exists.
|
||||
* DeleteBlobContainerResult.Deleted is false if the container doesn't exist.
|
||||
*/
|
||||
Azure::Core::Response<Models::DeleteBlobContainerResult> DeleteIfExists(
|
||||
const DeleteBlobContainerOptions& options = DeleteBlobContainerOptions()) const;
|
||||
|
||||
@ -125,8 +125,8 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
* @param blobContentLength Specifies the maximum size for the page blob. The size must be
|
||||
* aligned to a 512-byte boundary.
|
||||
* @param options Optional parameters to execute this function.
|
||||
* @return A CreatePageBlobResult describing the newly created page blob. Null if the blob
|
||||
* already exists.
|
||||
* @return A CreatePageBlobResult describing the newly created page blob.
|
||||
* CreatePageBlobResult.Created is false if the blob already exists.
|
||||
*/
|
||||
Azure::Core::Response<Models::CreatePageBlobResult> CreateIfNotExists(
|
||||
int64_t blobContentLength,
|
||||
|
||||
@ -297,6 +297,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
struct CreateAppendBlobResult
|
||||
{
|
||||
bool Created = true;
|
||||
std::string ETag;
|
||||
Azure::Core::DateTime LastModified;
|
||||
Azure::Core::Nullable<std::string> VersionId;
|
||||
@ -307,6 +308,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
struct CreateBlobContainerResult
|
||||
{
|
||||
bool Created = true;
|
||||
std::string ETag;
|
||||
Azure::Core::DateTime LastModified;
|
||||
}; // struct CreateBlobContainerResult
|
||||
@ -324,6 +326,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
struct CreatePageBlobResult
|
||||
{
|
||||
bool Created = true;
|
||||
std::string ETag;
|
||||
Azure::Core::DateTime LastModified;
|
||||
Azure::Core::Nullable<std::string> VersionId;
|
||||
@ -335,10 +338,12 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
|
||||
struct DeleteBlobContainerResult
|
||||
{
|
||||
bool Deleted = true;
|
||||
}; // struct DeleteBlobContainerResult
|
||||
|
||||
struct DeleteBlobResult
|
||||
{
|
||||
bool Deleted = true;
|
||||
}; // struct DeleteBlobResult
|
||||
|
||||
class DeleteSnapshotsOption {
|
||||
|
||||
@ -110,7 +110,9 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (e.StatusCode == Core::Http::HttpStatusCode::Conflict
|
||||
&& e.ErrorCode == "BlobAlreadyExists")
|
||||
{
|
||||
return Azure::Core::Response<Models::CreateAppendBlobResult>(std::move(e.RawResponse));
|
||||
Models::CreateAppendBlobResult ret;
|
||||
ret.Created = false;
|
||||
return Azure::Core::Response<Models::CreateAppendBlobResult>(std::move(ret), std::move(e.RawResponse));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -634,7 +634,9 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (e.StatusCode == Core::Http::HttpStatusCode::NotFound
|
||||
&& (e.ErrorCode == "BlobNotFound" || e.ErrorCode == "ContainerNotFound"))
|
||||
{
|
||||
return Azure::Core::Response<Models::DeleteBlobResult>(std::move(e.RawResponse));
|
||||
Models::DeleteBlobResult ret;
|
||||
ret.Deleted = false;
|
||||
return Azure::Core::Response<Models::DeleteBlobResult>(std::move(ret), std::move(e.RawResponse));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -163,7 +163,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (e.StatusCode == Core::Http::HttpStatusCode::Conflict
|
||||
&& e.ErrorCode == "ContainerAlreadyExists")
|
||||
{
|
||||
return Azure::Core::Response<Models::CreateBlobContainerResult>(std::move(e.RawResponse));
|
||||
Models::CreateBlobContainerResult ret;
|
||||
ret.Created = false;
|
||||
return Azure::Core::Response<Models::CreateBlobContainerResult>(
|
||||
std::move(ret), std::move(e.RawResponse));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
@ -192,7 +195,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (e.StatusCode == Core::Http::HttpStatusCode::NotFound
|
||||
&& e.ErrorCode == "ContainerNotFound")
|
||||
{
|
||||
return Azure::Core::Response<Models::DeleteBlobContainerResult>(std::move(e.RawResponse));
|
||||
Models::DeleteBlobContainerResult ret;
|
||||
ret.Deleted = false;
|
||||
return Azure::Core::Response<Models::DeleteBlobContainerResult>(
|
||||
std::move(ret), std::move(e.RawResponse));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -117,7 +117,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (e.StatusCode == Core::Http::HttpStatusCode::Conflict
|
||||
&& e.ErrorCode == "BlobAlreadyExists")
|
||||
{
|
||||
return Azure::Core::Response<Models::CreatePageBlobResult>(std::move(e.RawResponse));
|
||||
Models::CreatePageBlobResult ret;
|
||||
ret.Created = false;
|
||||
return Azure::Core::Response<Models::CreatePageBlobResult>(
|
||||
std::move(ret), std::move(e.RawResponse));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -340,14 +340,14 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_THROW(blobClientWithoutAuth.CreateIfNotExists(), StorageException);
|
||||
{
|
||||
auto response = blobClient.CreateIfNotExists();
|
||||
EXPECT_TRUE(response.HasValue());
|
||||
EXPECT_TRUE(response->Created);
|
||||
}
|
||||
auto blobContent
|
||||
= Azure::Core::Http::MemoryBodyStream(m_blobContent.data(), m_blobContent.size());
|
||||
blobClient.AppendBlock(&blobContent);
|
||||
{
|
||||
auto response = blobClient.CreateIfNotExists();
|
||||
EXPECT_FALSE(response.HasValue());
|
||||
EXPECT_FALSE(response->Created);
|
||||
}
|
||||
auto downloadStream = std::move(blobClient.Download()->BodyStream);
|
||||
EXPECT_EQ(
|
||||
|
||||
@ -79,19 +79,19 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
StandardStorageConnectionString(), LowercaseRandomString());
|
||||
{
|
||||
auto response = container_client.DeleteIfExists();
|
||||
EXPECT_FALSE(response.HasValue());
|
||||
EXPECT_FALSE(response->Deleted);
|
||||
}
|
||||
{
|
||||
auto response = container_client.CreateIfNotExists();
|
||||
EXPECT_TRUE(response.HasValue());
|
||||
EXPECT_TRUE(response->Created);
|
||||
}
|
||||
{
|
||||
auto response = container_client.CreateIfNotExists();
|
||||
EXPECT_FALSE(response.HasValue());
|
||||
EXPECT_FALSE(response->Created);
|
||||
}
|
||||
{
|
||||
auto response = container_client.DeleteIfExists();
|
||||
EXPECT_TRUE(response.HasValue());
|
||||
EXPECT_TRUE(response->Deleted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -780,14 +780,14 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
auto blobClientWithoutAuth = Azure::Storage::Blobs::BlockBlobClient(blobClient.GetUrl());
|
||||
{
|
||||
auto response = blobClient.DeleteIfExists();
|
||||
EXPECT_FALSE(response.HasValue());
|
||||
EXPECT_FALSE(response->Deleted);
|
||||
}
|
||||
std::vector<uint8_t> emptyContent;
|
||||
blobClient.UploadFrom(emptyContent.data(), emptyContent.size());
|
||||
EXPECT_THROW(blobClientWithoutAuth.DeleteIfExists(), StorageException);
|
||||
{
|
||||
auto response = blobClient.DeleteIfExists();
|
||||
EXPECT_TRUE(response.HasValue());
|
||||
EXPECT_TRUE(response->Deleted);
|
||||
}
|
||||
|
||||
blobClient.UploadFrom(emptyContent.data(), emptyContent.size());
|
||||
@ -795,11 +795,11 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
auto blobClientWithSnapshot = blobClient.WithSnapshot(snapshot);
|
||||
{
|
||||
auto response = blobClientWithSnapshot.DeleteIfExists();
|
||||
EXPECT_TRUE(response.HasValue());
|
||||
EXPECT_TRUE(response->Deleted);
|
||||
}
|
||||
{
|
||||
auto response = blobClientWithSnapshot.DeleteIfExists();
|
||||
EXPECT_FALSE(response.HasValue());
|
||||
EXPECT_FALSE(response->Deleted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -264,7 +264,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_THROW(blobClientWithoutAuth.CreateIfNotExists(m_blobContent.size()), StorageException);
|
||||
{
|
||||
auto response = blobClient.CreateIfNotExists(m_blobContent.size());
|
||||
EXPECT_TRUE(response.HasValue());
|
||||
EXPECT_TRUE(response->Created);
|
||||
}
|
||||
|
||||
auto blobContent
|
||||
@ -272,7 +272,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
blobClient.UploadPages(0, &blobContent);
|
||||
{
|
||||
auto response = blobClient.CreateIfNotExists(m_blobContent.size());
|
||||
EXPECT_FALSE(response.HasValue());
|
||||
EXPECT_FALSE(response->Created);
|
||||
}
|
||||
auto downloadStream = std::move(blobClient.Download()->BodyStream);
|
||||
EXPECT_EQ(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user