Merge pull request #5728 from krwq/2017-02-15-attempt-to-fix-intermittent-failures

Attempt to fix intermittent failures with ...CLIRetriesLaunchingTheCommandForAtLeastOneSecond
This commit is contained in:
Piotr Puszkiewicz 2017-02-15 21:33:42 -08:00 committed by GitHub
commit 1f026bc530
2 changed files with 21 additions and 9 deletions

View file

@ -5,12 +5,15 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.Common;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
using NuGet.Configuration; using NuGet.Configuration;
using NuGet.Frameworks; using NuGet.Frameworks;
using NuGet.ProjectModel; using NuGet.ProjectModel;
using NuGet.Versioning; using NuGet.Versioning;
using ConcurrencyUtilities = NuGet.Common.ConcurrencyUtilities;
namespace Microsoft.DotNet.Cli.Utils namespace Microsoft.DotNet.Cli.Utils
{ {
@ -220,6 +223,15 @@ namespace Microsoft.DotNet.Cli.Utils
return null; return null;
} }
private static async Task<bool> FileExistsWithLock(string path)
{
return await ConcurrencyUtilities.ExecuteWithFileLockedAsync(
path,
lockedToken => Task.FromResult(File.Exists(path)),
CancellationToken.None);
}
private bool TryGetToolLockFile( private bool TryGetToolLockFile(
SingleProjectInfo toolLibrary, SingleProjectInfo toolLibrary,
string nugetPackagesRoot, string nugetPackagesRoot,
@ -228,7 +240,7 @@ namespace Microsoft.DotNet.Cli.Utils
lockFile = null; lockFile = null;
var lockFilePath = GetToolLockFilePath(toolLibrary, nugetPackagesRoot); var lockFilePath = GetToolLockFilePath(toolLibrary, nugetPackagesRoot);
if (!File.Exists(lockFilePath)) if (!FileExistsWithLock(lockFilePath).Result)
{ {
return false; return false;
} }

View file

@ -20,18 +20,18 @@ namespace Microsoft.DotNet.Cli.Utils
public static async Task<LockFile> ReadWithLock(this LockFileFormat subject, string path) public static async Task<LockFile> ReadWithLock(this LockFileFormat subject, string path)
{ {
if(!File.Exists(path))
{
throw new GracefulException(string.Join(
Environment.NewLine,
string.Format(LocalizableStrings.FileNotFound, path),
LocalizableStrings.ProjectNotRestoredOrRestoreFailed));
}
return await ConcurrencyUtilities.ExecuteWithFileLockedAsync( return await ConcurrencyUtilities.ExecuteWithFileLockedAsync(
path, path,
lockedToken => lockedToken =>
{ {
if (!File.Exists(path))
{
throw new GracefulException(string.Join(
Environment.NewLine,
string.Format(LocalizableStrings.FileNotFound, path),
LocalizableStrings.ProjectNotRestoredOrRestoreFailed));
}
var lockFile = FileAccessRetrier.RetryOnFileAccessFailure(() => subject.Read(path)); var lockFile = FileAccessRetrier.RetryOnFileAccessFailure(() => subject.Read(path));
return lockFile; return lockFile;