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
Prev Previous commit
Next Next commit
Hide WorkloadResolver.GetPackPath in favor of ResolvePackPath
Ensures aliased pack IDs are always resolved
  • Loading branch information
mhutch committed Jul 17, 2021
commit d867fef3540c3e125fb213037921dc686dd67435
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,9 @@ public IEnumerable<PackInfo> GetInstalledWorkloadPacksOfKind(WorkloadPackKind ki
continue;
}

if (ResolveId(pack) is WorkloadPackId resolvedPackageId)
if (ResolvePackPath(pack, out WorkloadPackId resolvedPackageId, out bool isInstalled) is string aliasedPath && isInstalled)
{
var aliasedPath = GetPackPath(_dotnetRootPaths, resolvedPackageId, pack.Version, pack.Kind, out bool isInstalled);
if (isInstalled)
{
yield return CreatePackInfo(pack, aliasedPath, resolvedPackageId);
}
yield return CreatePackInfo(pack, aliasedPath, resolvedPackageId);
}
}
}
Expand Down Expand Up @@ -251,57 +247,64 @@ internal void ReplaceFilesystemChecksForTest(Func<string, bool> fileExists, Func
/// <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, out bool isInstalled)
=> ResolvePackPath(pack, out _, out isInstalled);

private string? ResolvePackPath(
WorkloadPack pack,
out WorkloadPackId resolvedId,
out bool isInstalled)
{
if (ResolveId(pack) is WorkloadPackId resolvedId)
resolvedId = ResolveId(pack) ?? default;
if (resolvedId is WorkloadPackId resolved)
{
return GetPackPath(_dotnetRootPaths, resolvedId, pack.Version, pack.Kind, out isInstalled);
return GetPackPath(resolved, pack.Version, pack.Kind, out isInstalled);
}

isInstalled = false;
return null;
}

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)
string GetPackPath(WorkloadPackId resolvedPackageId, string packageVersion, WorkloadPackKind kind, out bool isInstalled)
{
switch (kind)
isInstalled = false;
string packPath = "";
bool isFile;
foreach (var rootPath in _dotnetRootPaths)
{
case WorkloadPackKind.Framework:
case WorkloadPackKind.Sdk:
packPath = Path.Combine(rootPath, "packs", packageId.ToString(), packageVersion);
isFile = false;
break;
case WorkloadPackKind.Template:
packPath = Path.Combine(rootPath, "template-packs", packageId.GetNuGetCanonicalId() + "." + packageVersion.ToLowerInvariant() + ".nupkg");
isFile = true;
break;
case WorkloadPackKind.Library:
packPath = Path.Combine(rootPath, "library-packs", packageId.GetNuGetCanonicalId() + "." + packageVersion.ToLowerInvariant() + ".nupkg");
isFile = true;
break;
case WorkloadPackKind.Tool:
packPath = Path.Combine(rootPath, "tool-packs", packageId.ToString(), packageVersion);
isFile = false;
break;
default:
throw new ArgumentException($"The package kind '{kind}' is not known", nameof(kind));
}
switch (kind)
{
case WorkloadPackKind.Framework:
case WorkloadPackKind.Sdk:
packPath = Path.Combine(rootPath, "packs", resolvedPackageId.ToString(), packageVersion);
isFile = false;
break;
case WorkloadPackKind.Template:
packPath = Path.Combine(rootPath, "template-packs", resolvedPackageId.GetNuGetCanonicalId() + "." + packageVersion.ToLowerInvariant() + ".nupkg");
isFile = true;
break;
case WorkloadPackKind.Library:
packPath = Path.Combine(rootPath, "library-packs", resolvedPackageId.GetNuGetCanonicalId() + "." + packageVersion.ToLowerInvariant() + ".nupkg");
isFile = true;
break;
case WorkloadPackKind.Tool:
packPath = Path.Combine(rootPath, "tool-packs", resolvedPackageId.ToString(), packageVersion);
isFile = false;
break;
default:
throw new ArgumentException($"The package kind '{kind}' is not known", nameof(kind));
}

//can we do a more robust check than directory.exists?
isInstalled = isFile ?
_fileExistOverride?.Invoke(packPath) ?? File.Exists(packPath) :
_directoryExistOverride?.Invoke(packPath) ?? Directory.Exists(packPath); ;
//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 (isInstalled)
{
break;
if (isInstalled)
{
break;
}
}
return packPath;
}
return packPath;
}

/// <summary>
Expand Down Expand Up @@ -414,11 +417,10 @@ public IEnumerable<WorkloadPackId> GetPacksInWorkload(WorkloadId workloadId)
throw new ArgumentException($"'{nameof(packId)}' cannot be null or empty", nameof(packId));
}

if (_packs.TryGetValue(new WorkloadPackId (packId)) is (WorkloadPack pack, _))
if (_packs.TryGetValue(packId) is (WorkloadPack pack, _))
{
if (ResolveId(pack) is WorkloadPackId resolvedPackageId)
if (ResolvePackPath(pack, out WorkloadPackId resolvedPackageId, out bool isInstalled) is string aliasedPath)
{
var aliasedPath = GetPackPath(_dotnetRootPaths, resolvedPackageId, pack.Version, pack.Kind, out _);
return CreatePackInfo(pack, aliasedPath, resolvedPackageId);
}
}
Expand Down