From 31ecb0378a6413d1d9a9bcf806d090d69b26f15b Mon Sep 17 00:00:00 2001 From: Jimmy Lewis Date: Thu, 20 Mar 2025 00:19:30 -0700 Subject: [PATCH] Fix RestoreTask tallying of written files During the switch to using LibraryInstallationGoalState, we changed the behavior of taking a LibraryInstallationState and "updating" it to reflect the published files (this transform would expand the Files from globs to a full list). That's inherently done by GoalState now, which also takes into account the FileMappings, and produces a set of the destination files. This was somehow overlooked in this build task, which caused it to throw a NRE when it was looking at the LibraryInstallationState (now that it wasn't being "updated", the Files were empty in many cases). This fix re-computes each successful LibraryInstallationState into the LibraryInstallationGoalState, which contains the list of files that were installed by that library. --- src/LibraryManager.Build/RestoreTask.cs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/LibraryManager.Build/RestoreTask.cs b/src/LibraryManager.Build/RestoreTask.cs index 6d434cb9..ebe461fd 100644 --- a/src/LibraryManager.Build/RestoreTask.cs +++ b/src/LibraryManager.Build/RestoreTask.cs @@ -73,7 +73,7 @@ public override bool Execute() if (!validationResults.All(r => r.Success)) { sw.Stop(); - LogErrors(validationResults.SelectMany(r =>r.Errors)); + LogErrors(validationResults.SelectMany(r => r.Errors)); return false; } @@ -82,7 +82,7 @@ public override bool Execute() sw.Stop(); FlushLogger(logger); - PopulateFilesWritten(results, dependencies.GetHostInteractions()); + PopulateFilesWritten(results, dependencies); LogResults(sw, results); return !Log.HasLoggedErrors; @@ -113,8 +113,7 @@ private void LogResults(Stopwatch sw, IEnumerable resul } else { - int fileCount = results.Where(r => r.Success).Sum(r => r.InstallationState.Files.Count); - if (fileCount > 0) + if (FilesWritten.Length > 0) { string text = string.Format(Resources.Text.Restore_NumberOfLibrariesSucceeded, results.Count(), Math.Round(sw.Elapsed.TotalSeconds, 2)); Log.LogMessage(MessageImportance.Normal, Environment.NewLine + text + Environment.NewLine); @@ -137,23 +136,18 @@ private void LogErrors(IEnumerable errors) Log.LogMessage(MessageImportance.High, Environment.NewLine + text + Environment.NewLine); } - private void PopulateFilesWritten(IEnumerable results, IHostInteraction hostInteraction) + private void PopulateFilesWritten(IEnumerable results, Dependencies dependencies) { IEnumerable states = results.Where(r => r.Success).Select(r => r.InstallationState); var list = new List(); foreach (ILibraryInstallationState state in states) { - foreach (string file in state.Files) + IProvider provider = dependencies.GetProvider(state.ProviderId); + OperationResult goalStateResult = provider.GetInstallationGoalStateAsync(state, CancellationToken.None).Result; + if (goalStateResult.Success) { - string absolutePath = Path.Combine(hostInteraction.WorkingDirectory, state.DestinationPath, file); - var absolute = new FileInfo(absolutePath); - - if (absolute.Exists) - { - string relative = absolute.FullName.Replace(ProjectDirectory, string.Empty).TrimStart('/', '\\'); - list.Add(new TaskItem(relative)); - } + list.AddRange(goalStateResult.Result.InstalledFiles.Select(f => new TaskItem(f.Key))); } }