-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #743 from jimmylewis/goalstate
Introduce LibraryInstallationGoalState
- Loading branch information
Showing
15 changed files
with
555 additions
and
128 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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.