Merge pull request #2774 from sokket/publish

Fixing error where lock could not be taken on build folder
This commit is contained in:
Jonathan Miller 2016-04-29 17:51:53 -07:00
commit ead9441318
2 changed files with 17 additions and 1 deletions

View file

@ -60,7 +60,9 @@ namespace Microsoft.DotNet.Cli.Build
{ {
string targetContainer = $"{Channel}/Binaries/Latest/"; string targetContainer = $"{Channel}/Binaries/Latest/";
string targetVersionFile = $"{targetContainer}{CliNuGetVersion}"; string targetVersionFile = $"{targetContainer}{CliNuGetVersion}";
string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(targetContainer); string semaphoreBlob = $"{Channel}/Binaries/publishSemaphore";
AzurePublisherTool.CreateBlobIfNotExists(semaphoreBlob);
string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(semaphoreBlob);
// Prevent race conditions by dropping a version hint of what version this is. If we see this file // Prevent race conditions by dropping a version hint of what version this is. If we see this file
// and it is the same as our version then we know that a race happened where two+ builds finished // and it is the same as our version then we know that a race happened where two+ builds finished

View file

@ -125,6 +125,20 @@ namespace Microsoft.DotNet.Cli.Build
} }
} }
public void CreateBlobIfNotExists(string path)
{
System.Threading.Tasks.Task<bool> task = _blobContainer.GetBlockBlobReference(path).ExistsAsync();
task.Wait();
if (!task.Result)
{
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(path);
using (MemoryStream ms = new MemoryStream())
{
blob.UploadFromStreamAsync(ms).Wait();
}
}
}
public void DeleteBlob(string path) public void DeleteBlob(string path)
{ {
_blobContainer.GetBlockBlobReference(path).DeleteAsync().Wait(); _blobContainer.GetBlockBlobReference(path).DeleteAsync().Wait();