Skip to content

Commit

Permalink
fix #6 add lock to Ensure...
Browse files Browse the repository at this point in the history
  • Loading branch information
pofider committed Jan 26, 2016
1 parent 38d312a commit ee1398a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions AzureBlobFileSystem/AzureBlobStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CloudBlobContainer> Containers { get; private set; }
public Func<string, CloudBlobContainer> ContainerFactory;
Expand All @@ -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://"))
Expand Down

0 comments on commit ee1398a

Please sign in to comment.