From 39d7442014c88490f72b7ecb8692a663986a77e8 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Sat, 18 Dec 2010 22:30:28 +0100 Subject: [PATCH] Fixing folder creation on Azure --HG-- branch : 1.x --- .../Media/AzureBlobStorageProviderTests.cs | 15 +++++++++++++++ src/Orchard.Azure/AzureFileSystem.cs | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs index 256c7c505..003e5fff4 100644 --- a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs +++ b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs @@ -165,6 +165,21 @@ namespace Orchard.Azure.Tests.FileSystems.Media { Assert.AreEqual(1, _azureBlobStorageProvider.ListFiles("folder1/folder4/folder3").Count()); } + [Test] + [ExpectedException(typeof(ArgumentException))] + public void CannotCreateAlreadyExistingFolders() + { + _azureBlobStorageProvider.CreateFile("folder1/foo.txt"); + _azureBlobStorageProvider.CreateFolder("folder1"); + } + + [Test] + public void CanCreateAlreadyExistingFolder() + { + _azureBlobStorageProvider.CreateFile("folder1/foo.txt"); + _azureBlobStorageProvider.TryCreateFolder("folder1"); + } + [Test] public void ShouldReadWriteFiles() { const string teststring = "This is a test string."; diff --git a/src/Orchard.Azure/AzureFileSystem.cs b/src/Orchard.Azure/AzureFileSystem.cs index 519a7477c..82ef0f7ae 100644 --- a/src/Orchard.Azure/AzureFileSystem.cs +++ b/src/Orchard.Azure/AzureFileSystem.cs @@ -156,7 +156,13 @@ namespace Orchard.Azure { public void TryCreateFolder(string path) { EnsurePathIsRelative(path); - CreateFile(Combine(path, FolderEntry)); + using (new HttpContextWeaver()) { + if (Container.DirectoryExists(String.Concat(_root, path))) { + return; + } + + CreateFile(Combine(path, FolderEntry)); + } } public void CreateFolder(string path) {