Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f9d957f
Eliminate redundant existence checks in workload resolver
mhutch Jun 3, 2021
b8ade8e
Implement workload redirects
mhutch Jun 9, 2021
a22e8d0
Fix 'avaliable' typo
mhutch Jun 9, 2021
e7a3eb2
Allow deferred opening of workload manifest stream
mhutch Jun 9, 2021
cf013d2
Add workload resolver method to determine updated workloads
mhutch Jun 9, 2021
3374ec9
Replace workload TempDirResolver with more generic OverlayResolver
mhutch Jun 10, 2021
0a8238c
Improve diagnosability of manifest conflicts
mhutch Jun 10, 2021
accd669
Improve workload composition errors
mhutch Jun 22, 2021
ed81dd4
Nullability checks in workload manifest reader tests
mhutch Jun 22, 2021
3d64056
Stronger typing of workload/pack ids in public API
mhutch Jun 22, 2021
a6cd134
Disable workload redirects for now
mhutch Jul 1, 2021
0254d95
Improve WorkloadResolver.GetPacksInWorkload
mhutch Jul 2, 2021
15d527f
Fix available workloads returned by resolver
mhutch Jul 2, 2021
619304d
Include workload ID in exception when resolver cannot find it
mhutch Jul 2, 2021
d867fef
Hide WorkloadResolver.GetPackPath in favor of ResolvePackPath
mhutch Jul 2, 2021
536f67c
When suggesting workloads, only consider available workloads
mhutch Jul 2, 2021
e4b36e3
Localize remaining workload composition errors
mhutch Jul 13, 2021
d75137c
Simplify WorkloadResolver.GetInstalledManifests
mhutch Jul 14, 2021
c9d64aa
Fix ResolvePackPath returning empty workload pack ids
mhutch Jul 15, 2021
48720b8
Check updated composition error messages in workload tests
mhutch Jul 15, 2021
0537ca7
Don't assume missing workload packs can always be satisfied
mhutch Jul 17, 2021
f4ed4c7
Fix accidental removal that broke workload search tests
mhutch Jul 19, 2021
b736168
Fix error message argument indices
dsplaisted Jul 18, 2021
4d4f3ef
Fix workload mocks to use correct manifest IDs
dsplaisted Jul 18, 2021
9f15943
Update test now that mock workload manifest has right ID
dsplaisted Jul 19, 2021
88fc6b4
Generate correct error message when trying to install a workload whic…
dsplaisted Jul 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Eliminate redundant existence checks in workload resolver
  • Loading branch information
mhutch committed Jul 17, 2021
commit f9d957fc996fcc57d08da1b09e3b4091645c0c99
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,20 @@ public void RefreshWorkloadManifests()
/// </remarks>
public IEnumerable<PackInfo> GetInstalledWorkloadPacksOfKind(WorkloadPackKind kind)
{
foreach (var pack in _packs)
foreach (var pack in _packs.Values)
{
if (pack.Value.Kind != kind)
if (pack.Kind != kind)
{
continue;
}

var aliasedPath = ResolvePackPath(pack.Value);
var resolvedPackageId = pack.Value.IsAlias ? pack.Value.TryGetAliasForRuntimeIdentifiers(_currentRuntimeIdentifiers)?.ToString() : pack.Value.Id.ToString();
if (aliasedPath != null && resolvedPackageId != null && PackExists(aliasedPath, pack.Value.Kind))
if (ResolveId(pack) is WorkloadPackId resolvedPackageId)
{
yield return CreatePackInfo(pack.Value, aliasedPath, resolvedPackageId);
var aliasedPath = GetPackPath(_dotnetRootPaths, resolvedPackageId, pack.Version, pack.Kind, out bool isInstalled);
if (isInstalled)
{
yield return CreatePackInfo(pack, aliasedPath, resolvedPackageId);
}
}
}
}
Expand All @@ -162,58 +164,54 @@ internal void ReplaceFilesystemChecksForTest(Func<string, bool> fileExists, Func
_directoryExistOverride = directoryExists;
}

private PackInfo CreatePackInfo(WorkloadPack pack, string aliasedPath, string resolvedPackageId) => new PackInfo(
private PackInfo CreatePackInfo(WorkloadPack pack, string aliasedPath, WorkloadPackId resolvedPackageId) => new PackInfo(
pack.Id.ToString(),
pack.Version,
pack.Kind,
aliasedPath,
resolvedPackageId
resolvedPackageId.ToString()
);

private bool PackExists (string packPath, WorkloadPackKind packKind)
/// <summary>
/// Resolve the package ID for the host platform.
/// </summary>
/// <param name="pack">The workload pack</param>
/// <returns>The path to the pack, or null if the pack is not available on the host platform.</returns>
private WorkloadPackId? ResolveId(WorkloadPack pack)
{
switch (packKind)
if (!pack.IsAlias)
{
case WorkloadPackKind.Framework:
case WorkloadPackKind.Sdk:
case WorkloadPackKind.Tool:
//can we do a more robust check than directory.exists?
return _directoryExistOverride?.Invoke(packPath) ?? Directory.Exists(packPath);
case WorkloadPackKind.Library:
case WorkloadPackKind.Template:
return _fileExistOverride?.Invoke(packPath) ?? File.Exists(packPath);
default:
throw new ArgumentException($"The package kind '{packKind}' is not known", nameof(packKind));
return pack.Id;
}

if (pack.TryGetAliasForRuntimeIdentifiers(_currentRuntimeIdentifiers) is WorkloadPackId aliasedId)
{
return aliasedId;
}
}

return null;
}

/// <summary>
/// Resolve the pack path for the host platform.
/// </summary>
/// <param name="pack">The workload pack</param>
/// <param name="isInstalled">Whether the pack is installed</param>
/// <returns>The path to the pack, or null if the pack is not available on the host platform.</returns>
private string? ResolvePackPath(WorkloadPack pack)
private string? ResolvePackPath(WorkloadPack pack, out bool isInstalled)
{
var resolvedId = pack.Id;

if (pack.IsAlias)
if (ResolveId(pack) is WorkloadPackId resolvedId)
{
if (pack.TryGetAliasForRuntimeIdentifiers(_currentRuntimeIdentifiers) is WorkloadPackId aliasedId)
{
resolvedId = aliasedId;
}
else
{
return null;
}
return GetPackPath(_dotnetRootPaths, resolvedId, pack.Version, pack.Kind, out isInstalled);
}

return GetPackPath(_dotnetRootPaths, resolvedId, pack.Version, pack.Kind);
isInstalled = false;
return null;
}

private string GetPackPath(string [] dotnetRootPaths, WorkloadPackId packageId, string packageVersion, WorkloadPackKind kind)
private string GetPackPath(string [] dotnetRootPaths, WorkloadPackId packageId, string packageVersion, WorkloadPackKind kind, out bool isInstalled)
{
isInstalled = false;
string packPath = "";
bool isFile;
foreach (var rootPath in dotnetRootPaths)
Expand Down Expand Up @@ -241,15 +239,15 @@ private string GetPackPath(string [] dotnetRootPaths, WorkloadPackId packageId,
throw new ArgumentException($"The package kind '{kind}' is not known", nameof(kind));
}

bool packFound = isFile ?
//can we do a more robust check than directory.exists?
isInstalled = isFile ?
_fileExistOverride?.Invoke(packPath) ?? File.Exists(packPath) :
_directoryExistOverride?.Invoke(packPath) ?? Directory.Exists(packPath); ;

if (packFound)
if (isInstalled)
{
break;
}

}
return packPath;
}
Expand All @@ -262,9 +260,8 @@ private HashSet<WorkloadPackId> GetInstalledPacks()
var installedPacks = new HashSet<WorkloadPackId>();
foreach (var pack in _packs)
{
var packPath = ResolvePackPath(pack.Value);

if (packPath != null && PackExists(packPath, pack.Value.Kind))
ResolvePackPath(pack.Value, out bool isInstalled);
if (isInstalled)
{
installedPacks.Add(pack.Key);
}
Expand Down Expand Up @@ -349,11 +346,10 @@ IEnumerable<WorkloadPackId> ExpandPacks (WorkloadId workloadId)

if (_packs.TryGetValue(new WorkloadPackId (packId), out var pack))
{
var packPath = ResolvePackPath(pack);
var resolvedPackageId = pack.IsAlias ? pack.TryGetAliasForRuntimeIdentifiers(_currentRuntimeIdentifiers)?.ToString() : pack.Id.ToString();
if (packPath != null && resolvedPackageId != null)
if (ResolveId(pack) is WorkloadPackId resolvedPackageId)
{
return CreatePackInfo(pack, packPath, resolvedPackageId);
var aliasedPath = GetPackPath(_dotnetRootPaths, resolvedPackageId, pack.Version, pack.Kind, out bool exists);
return CreatePackInfo(pack, aliasedPath, resolvedPackageId);
}
}

Expand Down Expand Up @@ -397,6 +393,9 @@ public PackInfo(string id, string version, WorkloadPackKind kind, string path, s
ResolvedPackageId = resolvedPackageId;
}

/// <summary>
/// The workload pack ID. The NuGet package ID <see cref="ResolvedPackageId"/> may differ from this.
/// </summary>
public string Id { get; }

public string Version { get; }
Expand Down