Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ hcertstore
HCRYPTMSG
HGlobal
HGLOBAL
hardlinks
HIDECANCEL
hinternet
HKCU
Expand Down Expand Up @@ -236,7 +235,6 @@ Params
params
parentidx
pathpart
pathing
Pathto
PBYTE
pch
Expand Down
12 changes: 4 additions & 8 deletions doc/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ Added the contract version 30 `InstallOptions.InstallDependenciesOnly` property

## Bug Fixes

### Portable installer alias handling

Portable installs now preserve the original executable filename instead of renaming it when an alias is needed.
For aliases requested through `--rename`, `Commands`, or `PortableCommandAlias`, WinGet creates a hardlink alias and keeps the original file as the source executable.

This change resolves alias failures in non-symlinked scenarios, including cases where WinGet adds the install directory to `PATH` instead of creating links.
Because the alias is now created as an executable hardlink in the install location, command aliases remain available and consistent even when symlink creation is skipped.

### Minor Bug Fixes
* Deferred the portable hardlink-alias feature while retaining cleanup compatibility for aliases created by 1.30 previews. Unverifiable package PATH entries are preserved with guidance for manual review.
* Prevented portable PATH cleanup from changing unrelated entries that share a directory-name prefix.
* Prevented portable installation preparation failures from creating empty uninstall registrations or cleaning up an existing installation.
* Allowed portable installation retries to reuse an exact empty uninstall registration left by an earlier failure, without overwriting populated registrations.
* Fixed REST search results bypassing locally verifiable package filters and selectors. Extra manifests are retrieved only for complete source result sets of three or fewer packages. Normalized name/publisher criteria remain unvalidated client-side.
* Fixed installed-package matching incorrectly combining names and publishers from different manifest entries.
* Prevented unrestricted REST searches when a source declares all requested selectors unsupported.
Expand Down
185 changes: 97 additions & 88 deletions src/AppInstallerCLICore/PortableInstaller.cpp

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/AppInstallerCLICore/PortableInstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ namespace AppInstaller::CLI::Portable
void CommitToARPEntry(PortableValueName valueName, T value)
{
m_portableARPEntry.SetValue(valueName, value);
m_hasRegistrationWrites = true;
}

bool HasRegistrationWrites() const { return m_hasRegistrationWrites; }

bool PrepareForARPEntryRecovery() { return m_portableARPEntry.PrepareForRecovery(); }

std::filesystem::path GetPortableIndexFileName()
{
return Utility::ConvertToUTF16(GetProductCode() + ".db");
Expand All @@ -95,6 +100,7 @@ namespace AppInstaller::CLI::Portable

private:
PortableARPEntry m_portableARPEntry;
bool m_hasRegistrationWrites = false;
std::vector<AppInstaller::Portable::PortableFileEntry> m_desiredEntries;
std::vector<AppInstaller::Portable::PortableFileEntry> m_expectedEntries;
std::stringstream m_stream;
Expand All @@ -114,6 +120,6 @@ namespace AppInstaller::CLI::Portable
void RemoveInstallDirectory();

void AddToPathVariable(std::filesystem::path value);
void RemoveFromPathVariable(std::filesystem::path value, bool onlyIfEmpty);
void RemoveFromPathVariable(std::filesystem::path value);
};
}
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(PortableLinksMachine);
WINGET_DEFINE_RESOURCE_STRINGID(PortableLinksUser);
WINGET_DEFINE_RESOURCE_STRINGID(PortablePackageAlreadyExists);
WINGET_DEFINE_RESOURCE_STRINGID(PortablePathEntryPreserved);
WINGET_DEFINE_RESOURCE_STRINGID(PortableRegistryCollisionOverridden);
WINGET_DEFINE_RESOURCE_STRINGID(PortableRoot);
WINGET_DEFINE_RESOURCE_STRINGID(PortableRoot86);
Expand Down
65 changes: 19 additions & 46 deletions src/AppInstallerCLICore/Workflows/PortableFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "PortableFlow.h"
#include "PortableInstaller.h"
#include "WorkflowBase.h"
#include <map>
#include <winget/Filesystem.h>
#include <winget/PortableFileEntry.h>
#include <winget/PortableIndex.h>
Expand Down Expand Up @@ -136,7 +135,11 @@ namespace AppInstaller::CLI::Workflow
{
if (packageIdentifier != portableInstaller.WinGetPackageIdentifier || sourceIdentifier != portableInstaller.WinGetSourceIdentifier)
{
if (!context.Args.Contains(Execution::Args::Type::Force))
if (!portableInstaller.IsUpdate && portableInstaller.PrepareForARPEntryRecovery())
{
AICLI_LOG(CLI, Info, << "Reusing empty portable registration for " << portableInstaller.GetProductCode());
}
else if (!context.Args.Contains(Execution::Args::Type::Force))
{
AICLI_LOG(CLI, Error, << "Registry match failed, skipping write to uninstall registry");
context.Reporter.Error() << Resource::String::PortablePackageAlreadyExists << std::endl;
Expand Down Expand Up @@ -207,24 +210,20 @@ namespace AppInstaller::CLI::Workflow
{
portableInstaller.RecordToIndex = true;

// Build a map of installed target path → SHA256 as file entries are created,
// so nested installer files that need hardlinks can reuse the hash without re-reading from disk.
std::map<std::filesystem::path, std::string> fileHashes;

for (const auto& entry : std::filesystem::directory_iterator(installerPath))
{
std::filesystem::path entryPath = entry.path();
PortableFileEntry portableFile;
std::filesystem::path relativePath = std::filesystem::relative(entryPath, entryPath.parent_path());
std::filesystem::path targetPath = targetInstallDirectory / relativePath;

if (std::filesystem::is_directory(entryPath))
{
entries.emplace_back(PortableFileEntry::CreateDirectoryEntry(entryPath, targetPath));
entries.emplace_back(std::move(PortableFileEntry::CreateDirectoryEntry(entryPath, targetPath)));
}
else
{
const PortableFileEntry& fileEntry = entries.emplace_back(PortableFileEntry::CreateFileEntry(entryPath, targetPath, {}));
fileHashes[std::filesystem::weakly_canonical(targetPath)] = fileEntry.SHA256;
entries.emplace_back(std::move(PortableFileEntry::CreateFileEntry(entryPath, targetPath, {})));
}
}

Expand All @@ -238,44 +237,28 @@ namespace AppInstaller::CLI::Workflow
EnsurePathIsRelative(context, nestedInstallerFile.PortableCommandAlias, "PortableCommandAlias", ManifestError::PortableCommandAliasEscapesDirectory);
AICLI_RETURN_VALUE_IF_TERMINATED(context, {});

const std::filesystem::path& relativeFilePath = ConvertToUTF16(nestedInstallerFile.RelativeFilePath);
const std::filesystem::path& targetPath = targetInstallDirectory / relativeFilePath;
std::filesystem::path originalFilename = targetPath.filename();
const std::filesystem::path& targetPath = targetInstallDirectory / ConvertToUTF16(nestedInstallerFile.RelativeFilePath);

std::filesystem::path commandAlias;
if (nestedInstallerFile.PortableCommandAlias.empty())
{
commandAlias = originalFilename;
commandAlias = targetPath.filename();
}
else
{
commandAlias = ConvertToUTF16(nestedInstallerFile.PortableCommandAlias);
}

Filesystem::AppendExtension(commandAlias, ".exe");

// If alias differs from original filename, create hardlink
// Hardlink will be placed in the same directory as the original file to avoid pathing issues and same-volume restrictions
if (commandAlias != originalFilename)
{
std::filesystem::path hardlinkPath = targetPath.parent_path() / commandAlias;
auto it = fileHashes.find(std::filesystem::weakly_canonical(targetPath));
THROW_HR_IF_MSG(APPINSTALLER_CLI_ERROR_PORTABLE_INSTALL_FAILED, it == fileHashes.end(), "Hash not found for hardlink target: %ls", targetPath.c_str());
entries.emplace_back(PortableFileEntry::CreateHardlinkEntry(hardlinkPath, targetPath, it->second));
}
entries.emplace_back(PortableFileEntry::CreateSymlinkEntry(symlinkDirectory / commandAlias, targetPath));
entries.emplace_back(std::move(PortableFileEntry::CreateSymlinkEntry(symlinkDirectory / commandAlias, targetPath)));
}
}
else
{
// Non-archive portable case: single executable file
std::string_view renameArg = context.Args.GetArg(Execution::Args::Type::Rename);
const std::vector<string_t>& commands = context.Get<Execution::Data::Installer>()->Commands;
std::filesystem::path commandAlias = installerPath.filename();

std::filesystem::path originalFilename = installerPath.filename();
std::filesystem::path commandAlias = originalFilename;

// Determine the command alias from rename arg, commands, or use original filename
if (!commands.empty())
{
EnsurePathIsRelative(context, commands[0], "CommandAlias", ManifestError::PortableCommandAliasEscapesDirectory);
Expand All @@ -288,23 +271,11 @@ namespace AppInstaller::CLI::Workflow
{
commandAlias = ConvertToUTF16(renameArg);
}
AppInstaller::Filesystem::AppendExtension(commandAlias, ".exe");

Filesystem::AppendExtension(commandAlias, ".exe");

// Target path for the original file (keeps its original name)
const std::filesystem::path& targetFullPath = targetInstallDirectory / originalFilename;

// Create file entry for original (with original name) - this computes SHA256
std::string fileSha256 = Utility::SHA256::ConvertToString(Utility::SHA256::ComputeHashFromFile(installerPath));
entries.emplace_back(PortableFileEntry::CreateFileEntry(installerPath, targetFullPath, fileSha256));

// If alias differs from original filename, create hardlink
if (commandAlias != originalFilename)
{
std::filesystem::path hardlinkPath = targetInstallDirectory / commandAlias;
entries.emplace_back(PortableFileEntry::CreateHardlinkEntry(hardlinkPath, targetFullPath, fileSha256));
}
entries.emplace_back(PortableFileEntry::CreateSymlinkEntry(symlinkDirectory / commandAlias, targetFullPath));
const std::filesystem::path& targetFullPath = targetInstallDirectory / commandAlias;
entries.emplace_back(std::move(PortableFileEntry::CreateFileEntry(installerPath, targetFullPath, {})));
entries.emplace_back(std::move(PortableFileEntry::CreateSymlinkEntry(symlinkDirectory / commandAlias, targetFullPath)));
}

return entries;
Expand All @@ -318,6 +289,7 @@ namespace AppInstaller::CLI::Workflow
EnsureSupportForPortableInstallScope(context, portableInstaller.GetScope());
AICLI_RETURN_IF_TERMINATED(context);

bool installAttempted = false;
try
{
context.Reporter.Info() << Resource::String::InstallFlowStartingPackageInstall << std::endl;
Expand All @@ -340,6 +312,7 @@ namespace AppInstaller::CLI::Workflow
}
}

installAttempted = true;
portableInstaller.Install(installType);
context.Add<Execution::Data::CorrelatedAppsAndFeaturesEntries>({ portableInstaller.GetAppsAndFeaturesEntry() });
context.Add<Execution::Data::OperationReturnCode>(ERROR_SUCCESS);
Expand All @@ -349,7 +322,7 @@ namespace AppInstaller::CLI::Workflow
{
context.Add<Execution::Data::OperationReturnCode>(Workflow::HandleException(context, std::current_exception()));

if (!portableInstaller.IsUpdate)
if (installAttempted && !portableInstaller.IsUpdate && portableInstaller.HasRegistrationWrites())
{
context.Reporter.Warn() << Resource::String::PortableInstallFailed << std::endl;
portableInstaller.PrepareForCleanUp();
Expand Down
16 changes: 0 additions & 16 deletions src/AppInstallerCLIE2ETests/Helpers/TestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,6 @@ public static void VerifyPortablePackage(
Assert.That(isAddedToPath, Is.EqualTo(shouldExist), $"Expected path variable: {(installDirectoryAddedToPath ? installDir : symlinkDirectory)}{pathDiagnostics}");
}

/// <summary>
/// Check if a path value exists in PATH.
/// </summary>
/// <param name="value">Path value.</param>
/// <param name="scope">Scope.</param>
/// <returns>True if PATH contains the value.</returns>
public static bool PathContainsValue(string value, Scope scope = Scope.User)
{
RegistryKey baseKey = scope == Scope.User ? Registry.CurrentUser : Registry.LocalMachine;
string pathSubKey = scope == Scope.User ? Constants.PathSubKey_User : Constants.PathSubKey_Machine;
using RegistryKey environmentRegistryKey = baseKey.OpenSubKey(pathSubKey, true);
string currentPathValue = (string)environmentRegistryKey.GetValue("Path") ?? string.Empty;
string expectedValue = value.TrimEnd('\\') + ';';
return currentPathValue.Contains(expectedValue, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Copies log files to the path %TEMP%\E2ETestLogs.
/// </summary>
Expand Down
Loading
Loading