Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename file in single portable installs #3439

Merged
merged 2 commits into from
Aug 30, 2023
Merged
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
29 changes: 9 additions & 20 deletions src/AppInstallerCLICore/Workflows/PortableFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace AppInstaller::CLI::Workflow
for (const auto& nestedInstallerFile : nestedInstallerFiles)
{
const std::filesystem::path& targetPath = targetInstallDirectory / ConvertToUTF16(nestedInstallerFile.RelativeFilePath);

Trenly marked this conversation as resolved.
Show resolved Hide resolved
std::filesystem::path commandAlias;
if (nestedInstallerFile.PortableCommandAlias.empty())
{
Expand All @@ -215,31 +215,20 @@ namespace AppInstaller::CLI::Workflow
{
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 fileName;
std::filesystem::path commandAlias;

if (!renameArg.empty())
std::filesystem::path commandAlias = installerPath.filename();

if (!commands.empty())
{
fileName = commandAlias = ConvertToUTF16(renameArg);
commandAlias = ConvertToUTF16(commands[0]);
}
else
{
if (!commands.empty())
{
commandAlias = ConvertToUTF16(commands[0]);
}
else
{
commandAlias = installerPath.filename();
}

fileName = installerPath.filename();
if (!renameArg.empty())
{
commandAlias = ConvertToUTF16(renameArg);
}

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

const std::filesystem::path& targetFullPath = targetInstallDirectory / fileName;
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)));
}
Expand Down
5 changes: 4 additions & 1 deletion src/AppInstallerCLIE2ETests/Helpers/TestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ public static void VerifyPortablePackage(
bool shouldExist,
Scope scope = Scope.User)
{
// When portables are installed, if the exe path is inside a directory it will not be aliased
// if the exe path is at the root level, it will be aliased. Therefore, if either exist, the exe exists
string exePath = Path.Combine(installDir, filename);
bool exeExists = File.Exists(exePath);
string exeAliasedPath = Path.Combine(installDir, commandAlias);
bool exeExists = File.Exists(exePath) || File.Exists(exeAliasedPath);

string symlinkDirectory = GetPortableSymlinkDirectory(scope);
string symlinkPath = Path.Combine(symlinkDirectory, commandAlias);
Expand Down
Loading