Skip to content

Commit cb54a23

Browse files
committed
Fix for incorrect error log being generated when a call to GetFiles should return empty as the filter removed all files but the folder did exist
1 parent 8bc0353 commit cb54a23

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/UmbracoFileSystemProviders.Azure.Tests/AzureBlobFileSystemTestsBase.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) James Jackson-South and contributors. All rights reserved.
33
// Licensed under the Apache License, Version 2.0.
44
// </copyright>
5-
65
namespace Our.Umbraco.FileSystemProviders.Azure.Tests
76
{
87
using System;
@@ -352,6 +351,23 @@ public void TestGetFilesFromRoot()
352351
Assert.IsTrue(expected.SequenceEqual(actual));
353352
}
354353

354+
355+
/// <summary>
356+
/// Asserts that a invalid path parameter passed to GetFiles returns null
357+
/// </summary>
358+
[Test]
359+
public void TestGetFilesInvalidPath()
360+
{
361+
// Arrange
362+
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem();
363+
364+
// Act
365+
IEnumerable<string> actual = provider.GetFiles("/somethingmissing", "*.jpg");
366+
367+
// Assert
368+
Assert.IsNull(actual);
369+
}
370+
355371
/// <summary>
356372
/// Asserts that the file system correctly returns a sequence of files from the root
357373
/// container in the correct format via a filtered request.

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,16 @@ public IEnumerable<string> GetDirectories(string path)
460460
public IEnumerable<string> GetFiles(string path, string filter)
461461
{
462462
IEnumerable<IListBlobItem> blobs = this.cloudBlobContainer.ListBlobs(this.FixPath(path), true);
463-
return blobs.OfType<CloudBlockBlob>().Select(cd =>
463+
464+
var blobList = blobs as IList<IListBlobItem> ?? blobs.ToList();
465+
466+
if (!blobList.Any())
467+
{
468+
this.LogHelper.Error<AzureFileSystem>("Blob not found", new DirectoryNotFoundException($"Blob not found at '{path}'"));
469+
return null;
470+
}
471+
472+
return blobList.OfType<CloudBlockBlob>().Select(cd =>
464473
{
465474
string url = cd.Uri.AbsoluteUri;
466475

@@ -476,7 +485,6 @@ public IEnumerable<string> GetFiles(string path, string filter)
476485
return url.Substring(this.rootContainerUrl.Length);
477486
}
478487

479-
this.LogHelper.Error<AzureFileSystem>("Directory not found", new DirectoryNotFoundException($"Directory not found at '{path}' with filter '{filter}'"));
480488
return null;
481489
}).Where(x => x != null);
482490
}

0 commit comments

Comments
 (0)