diff --git a/src/LibraryManager.Contracts/LibraryInstallationGoalState.cs b/src/LibraryManager.Contracts/LibraryInstallationGoalState.cs index cac93d2d..4d9f4809 100644 --- a/src/LibraryManager.Contracts/LibraryInstallationGoalState.cs +++ b/src/LibraryManager.Contracts/LibraryInstallationGoalState.cs @@ -14,9 +14,10 @@ public class LibraryInstallationGoalState /// /// Initialize a new goal state from the desired installation state. /// - public LibraryInstallationGoalState(ILibraryInstallationState installationState) + public LibraryInstallationGoalState(ILibraryInstallationState installationState, Dictionary installedFiles) { InstallationState = installationState; + InstalledFiles = installedFiles; } /// @@ -27,7 +28,7 @@ public LibraryInstallationGoalState(ILibraryInstallationState installationState) /// /// Mapping from destination file to source file /// - public IDictionary InstalledFiles { get; } = new Dictionary(); + public IDictionary InstalledFiles { get; } /// /// Returns whether the goal is in an achieved state - that is, all files are up to date. diff --git a/src/LibraryManager/Providers/BaseProvider.cs b/src/LibraryManager/Providers/BaseProvider.cs index bc6fc2ea..496572ef 100644 --- a/src/LibraryManager/Providers/BaseProvider.cs +++ b/src/LibraryManager/Providers/BaseProvider.cs @@ -235,7 +235,6 @@ public async Task> GetInstallation private OperationResult GenerateGoalState(ILibraryInstallationState desiredState, ILibrary library) { - var goalState = new LibraryInstallationGoalState(desiredState); List errors = null; if (string.IsNullOrEmpty(desiredState.DestinationPath)) @@ -253,6 +252,7 @@ private OperationResult GenerateGoalState(ILibrary outFiles = FileGlobbingUtility.ExpandFileGlobs(desiredState.Files, library.Files.Keys); } + Dictionary installFiles = new(); if (library.GetInvalidFiles(outFiles.ToList()) is IReadOnlyList invalidFiles && invalidFiles.Count > 0) { @@ -275,9 +275,8 @@ private OperationResult GenerateGoalState(ILibrary string sourceFile = GetCachedFileLocalPath(desiredState, outFile); sourceFile = FileHelpers.NormalizePath(sourceFile); - // TODO: make goalState immutable // map destination back to the library-relative file it originated from - goalState.InstalledFiles.Add(destinationFile, sourceFile); + installFiles.Add(destinationFile, sourceFile); } if (errors is not null) @@ -285,6 +284,7 @@ private OperationResult GenerateGoalState(ILibrary return OperationResult.FromErrors([.. errors]); } + var goalState = new LibraryInstallationGoalState(desiredState, installFiles); return OperationResult.FromSuccess(goalState); } diff --git a/test/Microsoft.Web.LibraryManager.Vsix.Test/Shared/LibraryCommandServiceTest.cs b/test/Microsoft.Web.LibraryManager.Vsix.Test/Shared/LibraryCommandServiceTest.cs index 3713b70c..990a6de8 100644 --- a/test/Microsoft.Web.LibraryManager.Vsix.Test/Shared/LibraryCommandServiceTest.cs +++ b/test/Microsoft.Web.LibraryManager.Vsix.Test/Shared/LibraryCommandServiceTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; @@ -34,8 +35,11 @@ public async Task UninstallAsync_DeletesFilesFromDisk() Files = new[] { "test.js" }, DestinationPath = "testDestination", }; - var testGoalState = new LibraryInstallationGoalState(testInstallationState); - testGoalState.InstalledFiles.Add(Path.Combine(mockInteraction.WorkingDirectory, "testDestination", "test.js"), Path.Combine(mockInteraction.WorkingDirectory, "test.js")); + Dictionary installedFiles = new() + { + { Path.Combine(mockInteraction.WorkingDirectory, "testDestination", "test.js"), Path.Combine(mockInteraction.WorkingDirectory, "test.js")} + }; + var testGoalState = new LibraryInstallationGoalState(testInstallationState, installedFiles); var mockDependencies = new Dependencies(mockInteraction, new IProvider[] { new Mocks.Provider(mockInteraction)