Skip to content

Commit 682cc7f

Browse files
Merge branch 'support/12.0.x' into develop
2 parents 925b561 + 7b7a501 commit 682cc7f

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/Umbraco.StorageProviders.AzureBlob/IO/AzureBlobFileSystem.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public IEnumerable<string> GetDirectories(string path)
8484
{
8585
ArgumentNullException.ThrowIfNull(path);
8686

87-
return ListBlobs(GetDirectoryPath(path))
87+
return ListBlobs(path)
8888
.Where(x => x.IsPrefix)
8989
.Select(x => GetRelativePath($"/{x.Prefix}").Trim('/'));
9090
}
@@ -104,13 +104,9 @@ public void DeleteDirectory(string path, bool recursive)
104104
{
105105
ArgumentNullException.ThrowIfNull(path);
106106

107-
foreach (BlobHierarchyItem blob in ListBlobs(GetDirectoryPath(path)))
107+
foreach (BlobHierarchyItem blob in ListBlobs(path, true))
108108
{
109-
if (blob.IsPrefix)
110-
{
111-
DeleteDirectory(blob.Prefix, true);
112-
}
113-
else if (blob.IsBlob)
109+
if (blob.IsBlob)
114110
{
115111
_container.GetBlobClient(blob.Blob.Name).DeleteIfExists();
116112
}
@@ -123,7 +119,10 @@ public bool DirectoryExists(string path)
123119
{
124120
ArgumentNullException.ThrowIfNull(path);
125121

126-
return GetBlobClient(GetDirectoryPath(path)).Exists();
122+
// Try getting a single item/page
123+
Page<BlobHierarchyItem>? firstPage = ListBlobs(path).AsPages(pageSizeHint: 1).FirstOrDefault();
124+
125+
return firstPage?.Values.Count > 0;
127126
}
128127

129128
/// <inheritdoc />
@@ -148,7 +147,7 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
148147
BlobClient blob = GetBlobClient(path);
149148
if (!overrideIfExists && blob.Exists())
150149
{
151-
throw new InvalidOperationException($"A file at path '{path}' already exists");
150+
throw new InvalidOperationException($"A file at path '{path}' already exists.");
152151
}
153152

154153
var headers = new BlobHttpHeaders();
@@ -180,7 +179,7 @@ public void AddFile(string path, string physicalPath, bool overrideIfExists = tr
180179
BlobClient destinationBlob = GetBlobClient(path);
181180
if (!overrideIfExists && destinationBlob.Exists())
182181
{
183-
throw new InvalidOperationException($"A file at path '{path}' already exists");
182+
throw new InvalidOperationException($"A file at path '{path}' already exists.");
184183
}
185184

186185
BlobClient sourceBlob = GetBlobClient(physicalPath);
@@ -220,7 +219,7 @@ public IEnumerable<string> GetFiles(string path, string? filter)
220219
{
221220
ArgumentNullException.ThrowIfNull(path);
222221

223-
IEnumerable<string> files = ListBlobs(GetDirectoryPath(path)).Where(x => x.IsBlob).Select(x => x.Blob.Name);
222+
IEnumerable<string> files = ListBlobs(path).Where(x => x.IsBlob).Select(x => x.Blob.Name);
224223
if (!string.IsNullOrEmpty(filter) && filter != "*.*")
225224
{
226225
// TODO: Might be better to use a globbing library
@@ -331,7 +330,7 @@ public BlobClient GetBlobClient(string path)
331330
{
332331
ArgumentNullException.ThrowIfNull(path);
333332

334-
return _container.GetBlobClient(GetBlobPath(path));
333+
return _container.GetBlobClient(GetBlobName(path));
335334
}
336335

337336
/// <inheritdoc />
@@ -348,17 +347,15 @@ private static string GetRequestRootPath(AzureBlobFileSystemOptions options, IHo
348347
private static string EnsureUrlSeparatorChar(string path)
349348
=> path.Replace("\\", "/", StringComparison.InvariantCultureIgnoreCase);
350349

351-
private string GetDirectoryPath(string fullPathOrUrl)
350+
private Pageable<BlobHierarchyItem> ListBlobs(string path, bool recursive = false)
352351
{
353-
var path = GetFullPath(fullPathOrUrl);
352+
string? delimiter = recursive ? null : "/";
353+
string prefix = GetFullPath(path).EnsureEndsWith('/');
354354

355-
return path.Length == 0 ? path : path.EnsureEndsWith('/');
355+
return _container.GetBlobsByHierarchy(delimiter: delimiter, prefix: prefix);
356356
}
357357

358-
private Pageable<BlobHierarchyItem> ListBlobs(string path)
359-
=> _container.GetBlobsByHierarchy(prefix: path);
360-
361-
private string GetBlobPath(string path)
358+
private string GetBlobName(string path)
362359
{
363360
path = EnsureUrlSeparatorChar(path);
364361

version.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "13.0.0",
3+
"version": "13.0.1-alpha",
44
"assemblyVersion": {
55
"precision": "build"
66
},
@@ -21,4 +21,4 @@
2121
"tagName": "release-{version}",
2222
"branchName": "release/{version}"
2323
}
24-
}
24+
}

0 commit comments

Comments
 (0)