Skip to content

Commit bda2f3e

Browse files
Merge branch 'support/10.0.x' into support/12.0.x
2 parents e94a152 + 29bfa38 commit bda2f3e

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public AzureBlobFileSystem(AzureBlobFileSystemOptions options, IHostingEnvironme
5353
/// <exception cref="System.ArgumentNullException"><paramref name="blobContainerClient" /> is <c>null</c>.</exception>
5454
/// <exception cref="System.ArgumentNullException"><paramref name="ioHelper" /> is <c>null</c>.</exception>
5555
/// <exception cref="System.ArgumentNullException"><paramref name="contentTypeProvider" /> is <c>null</c>.</exception>
56+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "This parameter is only a part of the URL.")]
5657
public AzureBlobFileSystem(string rootUrl, BlobContainerClient blobContainerClient, IIOHelper ioHelper, IContentTypeProvider contentTypeProvider, string? containerRootPath = null)
5758
{
5859
ArgumentNullException.ThrowIfNull(rootUrl);
@@ -92,7 +93,7 @@ public IEnumerable<string> GetDirectories(string path)
9293
{
9394
ArgumentNullException.ThrowIfNull(path);
9495

95-
return ListBlobs(GetDirectoryPath(path))
96+
return ListBlobs(path)
9697
.Where(x => x.IsPrefix)
9798
.Select(x => GetRelativePath($"/{x.Prefix}").Trim('/'));
9899
}
@@ -112,13 +113,9 @@ public void DeleteDirectory(string path, bool recursive)
112113
{
113114
ArgumentNullException.ThrowIfNull(path);
114115

115-
foreach (BlobHierarchyItem blob in ListBlobs(GetDirectoryPath(path)))
116+
foreach (BlobHierarchyItem blob in ListBlobs(path, true))
116117
{
117-
if (blob.IsPrefix)
118-
{
119-
DeleteDirectory(blob.Prefix, true);
120-
}
121-
else if (blob.IsBlob)
118+
if (blob.IsBlob)
122119
{
123120
_container.GetBlobClient(blob.Blob.Name).DeleteIfExists();
124121
}
@@ -131,7 +128,10 @@ public bool DirectoryExists(string path)
131128
{
132129
ArgumentNullException.ThrowIfNull(path);
133130

134-
return GetBlobClient(GetDirectoryPath(path)).Exists();
131+
// Try getting a single item/page
132+
Page<BlobHierarchyItem>? firstPage = ListBlobs(path).AsPages(pageSizeHint: 1).FirstOrDefault();
133+
134+
return firstPage?.Values.Count > 0;
135135
}
136136

137137
/// <inheritdoc />
@@ -156,7 +156,7 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
156156
BlobClient blob = GetBlobClient(path);
157157
if (!overrideIfExists && blob.Exists())
158158
{
159-
throw new InvalidOperationException($"A file at path '{path}' already exists");
159+
throw new InvalidOperationException($"A file at path '{path}' already exists.");
160160
}
161161

162162
var headers = new BlobHttpHeaders();
@@ -188,7 +188,7 @@ public void AddFile(string path, string physicalPath, bool overrideIfExists = tr
188188
BlobClient destinationBlob = GetBlobClient(path);
189189
if (!overrideIfExists && destinationBlob.Exists())
190190
{
191-
throw new InvalidOperationException($"A file at path '{path}' already exists");
191+
throw new InvalidOperationException($"A file at path '{path}' already exists.");
192192
}
193193

194194
BlobClient sourceBlob = GetBlobClient(physicalPath);
@@ -228,7 +228,7 @@ public IEnumerable<string> GetFiles(string path, string? filter)
228228
{
229229
ArgumentNullException.ThrowIfNull(path);
230230

231-
IEnumerable<string> files = ListBlobs(GetDirectoryPath(path)).Where(x => x.IsBlob).Select(x => x.Blob.Name);
231+
IEnumerable<string> files = ListBlobs(path).Where(x => x.IsBlob).Select(x => x.Blob.Name);
232232
if (!string.IsNullOrEmpty(filter) && filter != "*.*")
233233
{
234234
// TODO: Might be better to use a globbing library
@@ -268,6 +268,7 @@ public bool FileExists(string path)
268268

269269
/// <inheritdoc />
270270
/// <exception cref="System.ArgumentNullException"><paramref name="fullPathOrUrl" /> is <c>null</c>.</exception>
271+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "This method is inherited from an interface.")]
271272
public string GetRelativePath(string fullPathOrUrl)
272273
{
273274
ArgumentNullException.ThrowIfNull(fullPathOrUrl);
@@ -298,6 +299,7 @@ public string GetFullPath(string path)
298299

299300
/// <inheritdoc />
300301
/// <exception cref="System.ArgumentNullException"><paramref name="path" /> is <c>null</c>.</exception>
302+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1055:URI-like return values should not be strings", Justification = "This method is inherited from an interface.")]
301303
public string GetUrl(string? path)
302304
{
303305
ArgumentNullException.ThrowIfNull(path);
@@ -338,7 +340,7 @@ public BlobClient GetBlobClient(string path)
338340
{
339341
ArgumentNullException.ThrowIfNull(path);
340342

341-
return _container.GetBlobClient(GetBlobPath(path));
343+
return _container.GetBlobClient(GetBlobName(path));
342344
}
343345

344346
/// <inheritdoc />
@@ -347,17 +349,15 @@ public BlobClient GetBlobClient(string path)
347349
private static string EnsureUrlSeparatorChar(string path)
348350
=> path.Replace("\\", "/", StringComparison.InvariantCultureIgnoreCase);
349351

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

354-
return path.Length == 0 ? path : path.EnsureEndsWith('/');
357+
return _container.GetBlobsByHierarchy(delimiter: delimiter, prefix: prefix);
355358
}
356359

357-
private IEnumerable<BlobHierarchyItem> ListBlobs(string path)
358-
=> _container.GetBlobsByHierarchy(prefix: path);
359-
360-
private string GetBlobPath(string path)
360+
private string GetBlobName(string path)
361361
{
362362
path = EnsureUrlSeparatorChar(path);
363363

version.json

Lines changed: 1 addition & 1 deletion
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": "12.1.0-alpha",
3+
"version": "12.0.1-alpha",
44
"assemblyVersion": {
55
"precision": "build"
66
},

0 commit comments

Comments
 (0)