-
Notifications
You must be signed in to change notification settings - Fork 87
Introduce LibraryInstallationGoalState #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb732f0
Introduce installation goal state
jimmylewis 4b79145
Use OperationGoalState for intermediate steps in Install and Generate…
jimmylewis b845a91
Change BaseProvider to use a public API for getting goal state.
jimmylewis c0de1fc
Check some special cases for URI paths instead of local file paths
jimmylewis 4e665b3
Expose logic for finding local cache path
jimmylewis d53986e
make goalstate immutable
jimmylewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/LibraryManager.Contracts/LibraryInstallationGoalState.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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; | ||
|
||
namespace Microsoft.Web.LibraryManager.Contracts | ||
{ | ||
/// <summary> | ||
/// Represents a goal state of deployed files mapped to their sources from the local cache | ||
/// </summary> | ||
public class LibraryInstallationGoalState | ||
{ | ||
/// <summary> | ||
/// Initialize a new goal state from the desired installation state. | ||
/// </summary> | ||
public LibraryInstallationGoalState(ILibraryInstallationState installationState, Dictionary<string, string> installedFiles) | ||
{ | ||
InstallationState = installationState; | ||
InstalledFiles = installedFiles; | ||
} | ||
|
||
/// <summary> | ||
/// The ILibraryInstallationState that this goal state was computed from. | ||
/// </summary> | ||
public ILibraryInstallationState InstallationState { get; } | ||
|
||
/// <summary> | ||
/// Mapping from destination file to source file | ||
/// </summary> | ||
public IDictionary<string, string> InstalledFiles { get; } | ||
|
||
/// <summary> | ||
/// Returns whether the goal is in an achieved state - that is, all files are up to date. | ||
/// </summary> | ||
/// <remarks> | ||
/// This is intended to serve as a fast check compared to restoring the files. | ||
/// If there isn't a faster way to verify that a file is up to date, this method should | ||
/// return false to indicate that a restore can't be skipped. | ||
/// </remarks> | ||
public bool IsAchieved() | ||
{ | ||
foreach (KeyValuePair<string, string> kvp in InstalledFiles) | ||
{ | ||
// If the source file is a remote Uri, we have no way to determine if it matches the installed file. | ||
// So we will always reinstall the library in this case. | ||
if (FileHelpers.IsHttpUri(kvp.Value)) | ||
{ | ||
return false; | ||
} | ||
|
||
var destinationFile = new FileInfo(kvp.Key); | ||
var cacheFile = new FileInfo(kvp.Value); | ||
|
||
if (!destinationFile.Exists || !cacheFile.Exists || !FileHelpers.AreFilesUpToDate(destinationFile, cacheFile)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the name "achieved" as a word to match "goal", but it seems like if http URLs can never be achieved, maybe the method name could be "IsLocallyAcheived" as opposed to an IsAchievedAsync(cancellationtoken) that would actually make network calls to try and verify. Thoughts?