Skip to content

Commit

Permalink
Fix BlobFileStore (#3336)
Browse files Browse the repository at this point in the history
Fixes #3280
  • Loading branch information
TFleury authored and sebastienros committed Mar 15, 2019
1 parent 6f42499 commit 023b3a9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ public async Task<IFileStoreEntry> GetDirectoryInfoAsync(string path)
{
await _verifyContainerTask;

var placeholderBlob = GetBlobReference(this.Combine(path, _directoryMarkerFileName));
var blobDirectory = GetBlobDirectoryReference(path);

if (await placeholderBlob.ExistsAsync())
if (path == string.Empty || await BlobDirectoryExists(blobDirectory))
{
var blobDirectory = GetBlobDirectoryReference(path);
return new BlobDirectory(path, _clock.UtcNow);
}
return null;
Expand Down Expand Up @@ -299,6 +298,21 @@ await placeholderBlob.UploadTextAsync(
"This is a directory marker file created by Orchard Core. It is safe to delete it.");
}

private async Task<bool> BlobDirectoryExists(CloudBlobDirectory blobDirectory)
{
// CloudBlobDirectory exists if it has at least one blob
BlobContinuationToken continuationToken = null;
var segment = await blobDirectory.ListBlobsSegmentedAsync(
useFlatBlobListing: false,
blobListingDetails: BlobListingDetails.None,
maxResults: 1,
currentToken: continuationToken,
options: null,
operationContext: null);

return segment.Results.Any();
}

private async Task CreateBasePathIfNotExistsAsync()
{
if (string.IsNullOrEmpty(_options.BasePath))
Expand Down

0 comments on commit 023b3a9

Please sign in to comment.