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:
Sebastien Ros
2010-10-20 17:30:30 -07:00
parent 75efbf5f0a
commit b7f6e70d29
2 changed files with 11 additions and 3 deletions

View File

@@ -88,7 +88,6 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
[Test]
[ExpectedException(typeof(ArgumentException))]
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.CreateFolder("folder");
}

View File

@@ -8,7 +8,10 @@ using Microsoft.WindowsAzure.StorageClient;
using Orchard.FileSystems.Media;
namespace Orchard.Azure {
public class AzureFileSystem {
public class AzureFileSystem
{
private const string FolderEntry = "$$$ORCHARD$$$.$$$";
public string ContainerName { get; protected set; }
private readonly CloudStorageAccount _storageAccount;
@@ -79,6 +82,10 @@ namespace Orchard.Azure {
{
foreach (var blobItem in BlobClient.ListBlobsWithPrefix(prefix).OfType<CloudBlockBlob>())
{
// ignore directory entries
if(blobItem.Uri.AbsoluteUri.EndsWith(FolderEntry))
continue;
yield return new AzureBlobFileStorage(blobItem);
}
}
@@ -117,7 +124,9 @@ namespace Orchard.Azure {
using (new HttpContextWeaver())
{
Container.EnsureDirectoryDoesNotExist(path);
Container.GetDirectoryReference(path);
// Creating a virtually hidden file to make the directory an existing concept
CreateFile(path + "/" + FolderEntry);
}
}