make goalstate immutable
This commit is contained in:
Родитель
4e665b3cc1
Коммит
d53986ed65
|
@ -14,9 +14,10 @@ namespace Microsoft.Web.LibraryManager.Contracts
|
|||
/// <summary>
|
||||
/// Initialize a new goal state from the desired installation state.
|
||||
/// </summary>
|
||||
public LibraryInstallationGoalState(ILibraryInstallationState installationState)
|
||||
public LibraryInstallationGoalState(ILibraryInstallationState installationState, Dictionary<string, string> installedFiles)
|
||||
{
|
||||
InstallationState = installationState;
|
||||
InstalledFiles = installedFiles;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -27,7 +28,7 @@ namespace Microsoft.Web.LibraryManager.Contracts
|
|||
/// <summary>
|
||||
/// Mapping from destination file to source file
|
||||
/// </summary>
|
||||
public IDictionary<string, string> InstalledFiles { get; } = new Dictionary<string, string>();
|
||||
public IDictionary<string, string> InstalledFiles { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the goal is in an achieved state - that is, all files are up to date.
|
||||
|
|
|
@ -247,7 +247,6 @@ namespace Microsoft.Web.LibraryManager.Providers
|
|||
|
||||
private OperationResult<LibraryInstallationGoalState> GenerateGoalState(ILibraryInstallationState desiredState, ILibrary library)
|
||||
{
|
||||
var goalState = new LibraryInstallationGoalState(desiredState);
|
||||
List<IError> errors = null;
|
||||
|
||||
if (string.IsNullOrEmpty(desiredState.DestinationPath))
|
||||
|
@ -265,6 +264,7 @@ namespace Microsoft.Web.LibraryManager.Providers
|
|||
outFiles = FileGlobbingUtility.ExpandFileGlobs(desiredState.Files, library.Files.Keys);
|
||||
}
|
||||
|
||||
Dictionary<string, string> installFiles = new();
|
||||
if (library.GetInvalidFiles(outFiles.ToList()) is IReadOnlyList<string> invalidFiles
|
||||
&& invalidFiles.Count > 0)
|
||||
{
|
||||
|
@ -287,9 +287,8 @@ namespace Microsoft.Web.LibraryManager.Providers
|
|||
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)
|
||||
|
@ -297,6 +296,7 @@ namespace Microsoft.Web.LibraryManager.Providers
|
|||
return OperationResult<LibraryInstallationGoalState>.FromErrors([.. errors]);
|
||||
}
|
||||
|
||||
var goalState = new LibraryInstallationGoalState(desiredState, installFiles);
|
||||
return OperationResult<LibraryInstallationGoalState>.FromSuccess(goalState);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ namespace Microsoft.Web.LibraryManager.Vsix.Test.Shared
|
|||
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<string, string> 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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче