Skip to content

Commit

Permalink
DeleteIfExistsAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
KSemenenko committed Oct 18, 2022
1 parent 3ffdff2 commit f435c8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Expand Up @@ -14,8 +14,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Product>Managed Code - Storage</Product>
<Version>2.1.8</Version>
<PackageVersion>2.1.8</PackageVersion>
<Version>2.1.9</Version>
<PackageVersion>2.1.9</PackageVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
Expand Down
16 changes: 11 additions & 5 deletions ManagedCode.Storage.Azure/AzureStorage.cs
Expand Up @@ -124,14 +124,20 @@ protected override async Task<Result> CreateContainerInternalAsync(CancellationT
{
try
{
_ = await StorageClient.CreateIfNotExistsAsync(PublicAccessType.BlobContainer, cancellationToken: cancellationToken);
await StorageClient.SetAccessPolicyAsync(StorageOptions.PublicAccessType, cancellationToken: cancellationToken);
_ = await StorageClient.CreateIfNotExistsAsync(PublicAccessType.BlobContainer, cancellationToken: cancellationToken);
var policy = await StorageClient.GetAccessPolicyAsync(cancellationToken: cancellationToken);
if (policy.Value.BlobPublicAccess != StorageOptions.PublicAccessType)
{
await StorageClient.SetAccessPolicyAsync(StorageOptions.PublicAccessType, cancellationToken: cancellationToken);
}

IsContainerCreated = true;

return Result.Succeed();
}
catch (Exception ex)
{
IsContainerCreated = false;
_logger?.LogError(ex.Message, ex);
return Result.Fail(ex);
}
Expand All @@ -146,7 +152,7 @@ protected override async Task<Result> DeleteDirectoryInternalAsync(string direct
foreach (var blob in blobs)
{
var blobClient = StorageClient.GetBlobClient(blob.Name);
await blobClient.DeleteAsync(DeleteSnapshotsOption.None, null, cancellationToken);
await blobClient.DeleteIfExistsAsync(DeleteSnapshotsOption.None, null, cancellationToken);
}

return Result.Succeed();
Expand Down Expand Up @@ -227,8 +233,8 @@ protected override async Task<Result<bool>> DeleteInternalAsync(DeleteOptions op
{
await EnsureContainerExist();
var blobClient = StorageClient.GetBlobClient(options.FullPath);
var response = await blobClient.DeleteAsync(DeleteSnapshotsOption.None, null, cancellationToken);
return Result<bool>.Succeed(!response.IsError);
var response = await blobClient.DeleteIfExistsAsync(DeleteSnapshotsOption.None, null, cancellationToken);
return Result<bool>.Succeed(response);
}
catch (RequestFailedException ex)
when (ex.Status is 404)
Expand Down

0 comments on commit f435c8c

Please sign in to comment.