Workaround for empty restore.txt file under .tam (#4771)

* For some reason, specially in CI, the restore.txt file under .tam is ending up empty. As a workaround for it, I am going to retry the restore if that happens.

* Change how we diff the existing files in the TAM by using the explicit list from the .txt file.

* Using Nuget ReplaceWithLock utility to get around a concurrency issue on windows.
This commit is contained in:
Livar 2016-11-18 19:28:38 -08:00 committed by Piotr Puszkiewicz
parent dd2fe2fac5
commit 05670d6d7f

View file

@ -9,6 +9,7 @@ using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions; using Microsoft.DotNet.PlatformAbstractions;
using NuGet.Common;
namespace Microsoft.DotNet.TestFramework namespace Microsoft.DotNet.TestFramework
{ {
@ -102,24 +103,22 @@ namespace Microsoft.DotNet.TestFramework
private void SaveInventory(FileInfo file, IEnumerable<FileInfo> inventory) private void SaveInventory(FileInfo file, IEnumerable<FileInfo> inventory)
{ {
StreamWriter writer; FileUtility.ReplaceWithLock(
filePath =>
if (file.Exists)
{
writer = file.AppendText();
}
else
{
writer = file.CreateText();
}
using(writer)
{
foreach (var path in inventory.Select(i => i.FullName))
{ {
writer.WriteLine(path); using (var stream =
} new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
} {
using (var writer = new StreamWriter(stream))
{
foreach (var path in inventory.Select(i => i.FullName))
{
writer.WriteLine(path);
}
}
}
},
file.FullName);
} }
private IEnumerable<FileInfo> GetFileList() private IEnumerable<FileInfo> GetFileList()
@ -141,14 +140,31 @@ namespace Microsoft.DotNet.TestFramework
internal IEnumerable<FileInfo> GetBuildFiles() internal IEnumerable<FileInfo> GetBuildFiles()
{ {
return GetInventory(_inventoryFiles.Build, GetRestoreFiles, DoBuild); return GetInventory(
_inventoryFiles.Build,
() =>
{
var preInventory = new List<FileInfo>(GetRestoreFiles());
preInventory.AddRange(GetSourceFiles());
return preInventory;
},
DoBuild);
} }
private IEnumerable<FileInfo> GetInventory(FileInfo file, Func<IEnumerable<FileInfo>> beforeAction, Action action) private IEnumerable<FileInfo> GetInventory(
FileInfo file,
Func<IEnumerable<FileInfo>> beforeAction,
Action action)
{ {
var inventory = Enumerable.Empty<FileInfo>();
if (file.Exists) if (file.Exists)
{ {
return LoadInventory(file); inventory = LoadInventory(file);
}
if(inventory.Any())
{
return inventory;
} }
IEnumerable<FileInfo> preInventory; IEnumerable<FileInfo> preInventory;
@ -159,14 +175,12 @@ namespace Microsoft.DotNet.TestFramework
} }
else else
{ {
beforeAction(); preInventory = beforeAction();
preInventory = GetFileList();
} }
action(); action();
var inventory = GetFileList().Where(i => !preInventory.Select(p => p.FullName).Contains(i.FullName)); inventory = GetFileList().Where(i => !preInventory.Select(p => p.FullName).Contains(i.FullName));
SaveInventory(file, inventory); SaveInventory(file, inventory);