1
+ using System . Net ;
1
2
using Azure ;
2
3
using Azure . Storage . Blobs ;
3
4
using Azure . Storage . Blobs . Models ;
@@ -12,6 +13,10 @@ namespace Umbraco.StorageProviders.AzureBlob.IO;
12
13
/// <inheritdoc />
13
14
public sealed class AzureBlobFileSystem : IAzureBlobFileSystem , IFileProviderFactory
14
15
{
16
+ // When not found, default to 1-1-1601 00:00:00 +00:00 for created/last modified and -1 for size to align with PhysicalFileSystem
17
+ private static readonly DateTimeOffset _notFoundDateTimeOffset = DateTimeOffset . FromUnixTimeSeconds ( - 11644473600 ) ;
18
+ private const long NotFoundSize = - 1 ;
19
+
15
20
private readonly string _requestRootPath ;
16
21
private readonly string _containerRootPath ;
17
22
private readonly BlobContainerClient _container ;
@@ -91,6 +96,9 @@ public IEnumerable<string> GetDirectories(string path)
91
96
92
97
/// <inheritdoc />
93
98
/// <exception cref="System.ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
99
+ /// <remarks>
100
+ /// Azure Blob Storage can only delete blobs, so deleting directories is always recursive.
101
+ /// </remarks>
94
102
public void DeleteDirectory ( string path )
95
103
{
96
104
ArgumentNullException . ThrowIfNull ( path ) ;
@@ -100,6 +108,9 @@ public void DeleteDirectory(string path)
100
108
101
109
/// <inheritdoc />
102
110
/// <exception cref="System.ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
111
+ /// <remarks>
112
+ /// Azure Blob Storage can only delete blobs, so deleting directories is always recursive.
113
+ /// </remarks>
103
114
public void DeleteDirectory ( string path , bool recursive )
104
115
{
105
116
ArgumentNullException . ThrowIfNull ( path ) ;
@@ -303,7 +314,14 @@ public DateTimeOffset GetLastModified(string path)
303
314
{
304
315
ArgumentNullException . ThrowIfNull ( path ) ;
305
316
306
- return GetBlobClient ( path ) . GetProperties ( ) . Value . LastModified ;
317
+ try
318
+ {
319
+ return GetBlobClient ( path ) . GetProperties ( ) . Value . LastModified ;
320
+ }
321
+ catch ( RequestFailedException ex ) when ( ex . Status == ( int ) HttpStatusCode . NotFound )
322
+ {
323
+ return _notFoundDateTimeOffset ;
324
+ }
307
325
}
308
326
309
327
/// <inheritdoc />
@@ -312,7 +330,14 @@ public DateTimeOffset GetCreated(string path)
312
330
{
313
331
ArgumentNullException . ThrowIfNull ( path ) ;
314
332
315
- return GetBlobClient ( path ) . GetProperties ( ) . Value . CreatedOn ;
333
+ try
334
+ {
335
+ return GetBlobClient ( path ) . GetProperties ( ) . Value . CreatedOn ;
336
+ }
337
+ catch ( RequestFailedException ex ) when ( ex . Status == ( int ) HttpStatusCode . NotFound )
338
+ {
339
+ return _notFoundDateTimeOffset ;
340
+ }
316
341
}
317
342
318
343
/// <inheritdoc />
@@ -321,7 +346,14 @@ public long GetSize(string path)
321
346
{
322
347
ArgumentNullException . ThrowIfNull ( path ) ;
323
348
324
- return GetBlobClient ( path ) . GetProperties ( ) . Value . ContentLength ;
349
+ try
350
+ {
351
+ return GetBlobClient ( path ) . GetProperties ( ) . Value . ContentLength ;
352
+ }
353
+ catch ( RequestFailedException ex ) when ( ex . Status == ( int ) HttpStatusCode . NotFound )
354
+ {
355
+ return NotFoundSize ;
356
+ }
325
357
}
326
358
327
359
/// <inheritdoc />
0 commit comments