Skip to content

Commit

Permalink
Fix "wix extension list" to correctly display machine-wide extensions
Browse files Browse the repository at this point in the history
Fixes 8625
  • Loading branch information
robmen committed Jul 15, 2024
1 parent 79417f8 commit 2981a1c
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions src/wix/WixToolset.Core.ExtensionCache/ExtensionCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,54 @@ public Task<IEnumerable<CachedExtension>> ListAsync(bool global, string extensio

(var extensionId, var extensionVersion) = ParseExtensionReference(extension);

var cacheFolder = this.GetCacheFolder(global);

var searchFolder = Path.Combine(cacheFolder, extensionId, extensionVersion);
var cacheFolders = this.GetCacheFolders(global);

if (!Directory.Exists(searchFolder))
{
}
else if (!String.IsNullOrEmpty(extensionVersion)) // looking for an explicit version of an extension.
foreach (var cacheFolder in cacheFolders)
{
var present = this.ExtensionFileExists(cacheFolder, extensionId, extensionVersion);
found.Add(new CachedExtension(extensionId, extensionVersion, !present));
}
else // looking for all versions of an extension or all versions of all extensions.
{
IEnumerable<string> foundExtensionIds;
var searchFolder = Path.Combine(cacheFolder, extensionId, extensionVersion);

if (String.IsNullOrEmpty(extensionId))
if (!Directory.Exists(searchFolder))
{
// Looking for all versions of all extensions.
foundExtensionIds = Directory.GetDirectories(cacheFolder).Select(folder => Path.GetFileName(folder)).ToList();
}
else
else if (!String.IsNullOrEmpty(extensionVersion)) // looking for an explicit version of an extension.
{
// Looking for all versions of a single extension.
var extensionFolder = Path.Combine(cacheFolder, extensionId);
foundExtensionIds = Directory.Exists(extensionFolder) ? new[] { extensionId } : Array.Empty<string>();
var present = this.ExtensionFileExists(cacheFolder, extensionId, extensionVersion);
found.Add(new CachedExtension(extensionId, extensionVersion, !present));
}

foreach (var foundExtensionId in foundExtensionIds)
else // looking for all versions of an extension or all versions of all extensions.
{
var extensionFolder = Path.Combine(cacheFolder, foundExtensionId);
IEnumerable<string> foundExtensionIds;

foreach (var folder in Directory.GetDirectories(extensionFolder))
if (String.IsNullOrEmpty(extensionId))
{
// Looking for all versions of all extensions.
foundExtensionIds = Directory.GetDirectories(cacheFolder).Select(folder => Path.GetFileName(folder)).ToList();
}
else
{
cancellationToken.ThrowIfCancellationRequested();
// Looking for all versions of a single extension.
var extensionFolder = Path.Combine(cacheFolder, extensionId);
foundExtensionIds = Directory.Exists(extensionFolder) ? new[] { extensionId } : Array.Empty<string>();
}

var foundExtensionVersion = Path.GetFileName(folder);
foreach (var foundExtensionId in foundExtensionIds)
{
var extensionFolder = Path.Combine(cacheFolder, foundExtensionId);

if (!NuGetVersion.TryParse(foundExtensionVersion, out _))
foreach (var foundExtensionVersionFolder in Directory.GetDirectories(extensionFolder))
{
continue;
}
cancellationToken.ThrowIfCancellationRequested();

var foundExtensionVersion = Path.GetFileName(foundExtensionVersionFolder);

var present = this.ExtensionFileExists(cacheFolder, foundExtensionId, foundExtensionVersion);
found.Add(new CachedExtension(foundExtensionId, foundExtensionVersion, !present));
if (!NuGetVersion.TryParse(foundExtensionVersion, out _))
{
continue;
}

var present = this.ExtensionFileExists(cacheFolder, foundExtensionId, foundExtensionVersion);
found.Add(new CachedExtension(foundExtensionId, foundExtensionVersion, !present));
}
}
}
}
Expand All @@ -149,6 +152,18 @@ private string GetCacheFolder(bool global)
return cacheLocation.Path;
}

private IEnumerable<string> GetCacheFolders(bool global)
{
if (this.cacheLocations == null)
{
this.cacheLocations = this.ExtensionManager.GetCacheLocations();
}

var cacheLocations = this.cacheLocations.Where(l => global || l.Scope == ExtensionCacheLocationScope.Project).OrderBy(l => l.Scope).Select(l => l.Path);

return cacheLocations;
}

private async Task<bool> DownloadAndExtractAsync(bool global, string id, string version, CancellationToken cancellationToken)
{
var logger = NullLogger.Instance;
Expand Down

0 comments on commit 2981a1c

Please sign in to comment.