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:
commit
1f026bc530
2 changed files with 21 additions and 9 deletions
|
@ -5,12 +5,15 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using NuGet.Configuration;
|
||||
using NuGet.Frameworks;
|
||||
using NuGet.ProjectModel;
|
||||
using NuGet.Versioning;
|
||||
using ConcurrencyUtilities = NuGet.Common.ConcurrencyUtilities;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
@ -220,6 +223,15 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
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(
|
||||
SingleProjectInfo toolLibrary,
|
||||
string nugetPackagesRoot,
|
||||
|
@ -228,7 +240,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
lockFile = null;
|
||||
var lockFilePath = GetToolLockFilePath(toolLibrary, nugetPackagesRoot);
|
||||
|
||||
if (!File.Exists(lockFilePath))
|
||||
if (!FileExistsWithLock(lockFilePath).Result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,18 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
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(
|
||||
path,
|
||||
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));
|
||||
|
||||
return lockFile;
|
||||
|
|
Loading…
Add table
Reference in a new issue