mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Handle Azure folder creation
- Azure Blobs don't handle folders, have to create a fake "hidden" file entry to simulate the folder exists --HG-- branch : dev
This commit is contained in:
@@ -88,7 +88,6 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
|
|||||||
[Test]
|
[Test]
|
||||||
[ExpectedException(typeof(ArgumentException))]
|
[ExpectedException(typeof(ArgumentException))]
|
||||||
public void CreateFolderThatExistsShouldThrow() {
|
public void CreateFolderThatExistsShouldThrow() {
|
||||||
// sebros: In Azure, the folder concept is just about checking files prefix. So until a file exists, a folder is nothing
|
|
||||||
_azureBlobStorageProvider.CreateFile("folder/foo.txt");
|
_azureBlobStorageProvider.CreateFile("folder/foo.txt");
|
||||||
_azureBlobStorageProvider.CreateFolder("folder");
|
_azureBlobStorageProvider.CreateFolder("folder");
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,10 @@ using Microsoft.WindowsAzure.StorageClient;
|
|||||||
using Orchard.FileSystems.Media;
|
using Orchard.FileSystems.Media;
|
||||||
|
|
||||||
namespace Orchard.Azure {
|
namespace Orchard.Azure {
|
||||||
public class AzureFileSystem {
|
public class AzureFileSystem
|
||||||
|
{
|
||||||
|
private const string FolderEntry = "$$$ORCHARD$$$.$$$";
|
||||||
|
|
||||||
public string ContainerName { get; protected set; }
|
public string ContainerName { get; protected set; }
|
||||||
|
|
||||||
private readonly CloudStorageAccount _storageAccount;
|
private readonly CloudStorageAccount _storageAccount;
|
||||||
@@ -79,6 +82,10 @@ namespace Orchard.Azure {
|
|||||||
{
|
{
|
||||||
foreach (var blobItem in BlobClient.ListBlobsWithPrefix(prefix).OfType<CloudBlockBlob>())
|
foreach (var blobItem in BlobClient.ListBlobsWithPrefix(prefix).OfType<CloudBlockBlob>())
|
||||||
{
|
{
|
||||||
|
// ignore directory entries
|
||||||
|
if(blobItem.Uri.AbsoluteUri.EndsWith(FolderEntry))
|
||||||
|
continue;
|
||||||
|
|
||||||
yield return new AzureBlobFileStorage(blobItem);
|
yield return new AzureBlobFileStorage(blobItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +124,9 @@ namespace Orchard.Azure {
|
|||||||
using (new HttpContextWeaver())
|
using (new HttpContextWeaver())
|
||||||
{
|
{
|
||||||
Container.EnsureDirectoryDoesNotExist(path);
|
Container.EnsureDirectoryDoesNotExist(path);
|
||||||
Container.GetDirectoryReference(path);
|
|
||||||
|
// Creating a virtually hidden file to make the directory an existing concept
|
||||||
|
CreateFile(path + "/" + FolderEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user