Skip to content

Commit

Permalink
#2928 fixed Azure blob storage basepath issue (#2948)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchenga authored and sebastienros committed Dec 31, 2018
1 parent 1be6ba2 commit 5c29b34
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public BlobFileStore(BlobStorageOptions options, IClock clock)
try
{
await _blobContainer.CreateIfNotExistsAsync();
await CreateBasePathIfNotExistsAsync();
await _blobContainer.SetPermissionsAsync(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });
}
catch (Exception ex)
Expand Down Expand Up @@ -159,14 +160,13 @@ public async Task<bool> TryCreateDirectoryAsync(string path)
if (await blob.ExistsAsync())
throw new FileStoreException($"Cannot create directory because the path '{path}' already exists and is a file.");

// Create a directory marker file to make this directory appear when
// listing directories.
var placeholderBlob = GetBlobReference(this.Combine(path, _directoryMarkerFileName));
await placeholderBlob.UploadTextAsync("This is a directory marker file created by Orchard Core. It is safe to delete it.");
await CreateDirectoryAsync(path);

return true;
}



public async Task<bool> TryDeleteFileAsync(string path)
{
await _verifyContainerTask;
Expand Down Expand Up @@ -287,5 +287,29 @@ private CloudBlobDirectory GetBlobDirectoryReference(string path)

return blobDirectory;
}

private async Task CreateDirectoryAsync(string path)
{
var placeholderBlob = GetBlobReference(this.Combine(path, _directoryMarkerFileName));


// Create a directory marker file to make this directory appear when
// listing directories.
await placeholderBlob.UploadTextAsync(
"This is a directory marker file created by Orchard Core. It is safe to delete it.");
}

private async Task CreateBasePathIfNotExistsAsync()
{
if (string.IsNullOrEmpty(_options.BasePath))
return;

var path = string.Empty;
var blob = GetBlobReference(path);
if (await blob.ExistsAsync())
return;

await CreateDirectoryAsync(path);
}
}
}

0 comments on commit 5c29b34

Please sign in to comment.