| | 1 | | // Copyright (c) Microsoft and contributors. All rights reserved. |
| | 2 | | // |
| | 3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
| | 4 | | // you may not use this file except in compliance with the License. |
| | 5 | | // You may obtain a copy of the License at |
| | 6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
| | 7 | | // |
| | 8 | | // Unless required by applicable law or agreed to in writing, software |
| | 9 | | // distributed under the License is distributed on an "AS IS" BASIS, |
| | 10 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | 11 | | // |
| | 12 | | // See the License for the specific language governing permissions and |
| | 13 | | // limitations under the License. |
| | 14 | |
|
| | 15 | | using Microsoft.WindowsAzure.Storage; |
| | 16 | | using Microsoft.WindowsAzure.Storage.Blob; |
| | 17 | | using System; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.Linq; |
| | 20 | | using System.Text; |
| | 21 | | using System.Threading.Tasks; |
| | 22 | |
|
| | 23 | | namespace Microsoft.Azure.Batch.Conventions.Files.Utilities |
| | 24 | | { |
| | 25 | | internal static class BlobUtils |
| | 26 | | { |
| | 27 | | internal static async Task EnsureExistsAsync(this CloudAppendBlob blob) |
| | 28 | | { |
| | 29 | | try |
| | 30 | | { |
| 0 | 31 | | await blob.CreateOrReplaceAsync(AccessCondition.GenerateIfNotExistsCondition(), null, null).ConfigureAwa |
| 0 | 32 | | } |
| 0 | 33 | | catch (StorageException ex) when (ex.StorageErrorCodeIs("BlobAlreadyExists")) |
| | 34 | | { |
| 0 | 35 | | } |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | internal static bool StorageErrorCodeIs(this StorageException ex, string errorCodeToTestFor) |
| | 39 | | { |
| 0 | 40 | | var errorCode = ex?.RequestInformation?.ExtendedErrorInformation?.ErrorCode; |
| | 41 | |
|
| 0 | 42 | | return errorCodeToTestFor.Equals(errorCode, StringComparison.OrdinalIgnoreCase); |
| | 43 | | } |
| | 44 | | } |
| | 45 | | } |