From ee1398ab1e587bc0bf314c76fb061f038481658c Mon Sep 17 00:00:00 2001 From: "honza.pofider@seznam.cz" Date: Tue, 26 Jan 2016 18:32:12 +0100 Subject: [PATCH] fix #6 add lock to Ensure... --- .../AzureBlobStorageProvider.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/AzureBlobFileSystem/AzureBlobStorageProvider.cs b/AzureBlobFileSystem/AzureBlobStorageProvider.cs index 379a16b..1f18292 100644 --- a/AzureBlobFileSystem/AzureBlobStorageProvider.cs +++ b/AzureBlobFileSystem/AzureBlobStorageProvider.cs @@ -14,6 +14,7 @@ namespace AzureBlobFileSystem public class AzureBlobStorageProvider : IStorageProvider { private readonly CloudStorageAccount _storageAccount; + private Object _lock = new Object(); public CloudBlobClient BlobClient { get; private set; } public IList Containers { get; private set; } public Func ContainerFactory; @@ -30,18 +31,22 @@ private CloudBlobContainer EnsurePathIsRelativeAndEnsureContainer(ref string pat { var containerName = path.Split('/').First(); - var container = Containers.SingleOrDefault(c => c.Name == containerName); - - if (container == null) + CloudBlobContainer container; + lock (_lock) { - container = BlobClient.GetContainerReference(containerName); - - if (!container.Exists()) + container = Containers.SingleOrDefault(c => c.Name == containerName); + + if (container == null) { - container = ContainerFactory(containerName); - } + container = BlobClient.GetContainerReference(containerName); - Containers.Add(container); + if (!container.Exists()) + { + container = ContainerFactory(containerName); + } + + Containers.Add(container); + } } if (path.StartsWith("/") || path.StartsWith("http://") || path.StartsWith("https://"))