Skip to content

Commit 3549e61

Browse files
committed
Fix for #200
(cherry picked from commit 92f702cf86a9dae1b1b6e90c3152dabc6c21534e)
1 parent 1b84658 commit 3549e61

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/UmbracoFileSystemProviders.Azure.Tests/AzureBlobFileSystemCommonTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,17 @@ public void TestGetSubDirectoriesNone()
639639
// Arrange
640640
AzureBlobFileSystem provider = this.CreateAzureBlobFileSystem(containerName: "forms-data");
641641
provider.AddFile("forms/b5e2fab3-040d-4328-ac74-cf7f7ebe3918.json", Stream.Null);
642+
provider.AddFile("workflows/b5e2fab3-040d-4328-ac74-cf7f7ebe3918.json", Stream.Null);
642643

643644
// Act
644645
IEnumerable<string> actual = provider.GetDirectories("forms");
645646

646647
// Assert
647648
string[] expected = { };
648649
Assert.IsTrue(expected.SequenceEqual(actual));
650+
651+
// Tidy up after test
652+
provider.DeleteDirectory("forms");
649653
}
650654
}
651655
}

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,13 @@ public IEnumerable<string> GetDirectories(string path)
518518
var directory = this.GetDirectoryReference(path);
519519

520520
var listedBlobs = directory.ListBlobs();
521-
var prefixes = listedBlobs.Where(blob => blob.IsPrefix).Select(x=>x.Prefix).ToList();
522-
var blobPrefixes = listedBlobs.Where(x => x.IsBlob && x.Blob.Name.LastIndexOf('/') >= 0).Select(x => x.Blob.Name.Substring(0, x.Blob.Name.LastIndexOf('/') + 1));
523-
524-
521+
var prefixes = listedBlobs.Where(blob => blob.IsPrefix).Select(x => x.Prefix).ToList();
522+
var blobPrefixes = listedBlobs.Where(x => x.IsBlob && x.Blob.Name.LastIndexOf('/') >= 0)
523+
.Select(x => x.Blob.Name.Substring(0, x.Blob.Name.LastIndexOf('/') + 1));
524+
525525
// Always get last segment for media sub folder simulation. E.g 1001, 1002
526-
var all = prefixes.Union(blobPrefixes);
526+
var all = prefixes.Union(blobPrefixes).Where(x => !x.Equals(path + "/"));
527+
527528
return all.Select(cd => cd.TrimEnd('/'));
528529
}
529530

@@ -853,7 +854,7 @@ private AzureBlobDirectory GetDirectoryReference(string path)
853854
Current.Logger.Debug<AzureBlobFileSystem>($"GetDirectoryReference(path) method executed with path:{path}");
854855

855856
string blobPath = this.FixPath(path);
856-
return new AzureBlobDirectory(cloudBlobContainer,blobPath);
857+
return new AzureBlobDirectory(cloudBlobContainer, blobPath);
857858
}
858859

859860
/// <summary>

0 commit comments

Comments
 (0)