Skip to content

Commit

Permalink
Skip uninstall attempt when installed package version is not present (#…
Browse files Browse the repository at this point in the history
…4685)

## Issue
We are seeing crashes from the installed package version being null, but
only during upgrades with a dependency when attempting to uninstall said
dependency (either due to user request or manifest).

## Change
Simply exit the two workflow tasks involved with the uninstall if the
installed package version is not present.
  • Loading branch information
JohnMcPMS authored Jul 30, 2024
1 parent e8e5f50 commit 32e3bf9
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/AppInstallerCLICore/Workflows/UninstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ namespace AppInstaller::CLI::Workflow
void GetUninstallInfo(Execution::Context& context)
{
auto installedPackageVersion = context.Get<Execution::Data::InstalledPackageVersion>();

if (!installedPackageVersion)
{
AICLI_LOG(CLI, Verbose, << "No installed package version; cannot get uninstall information.");
return;
}

const std::string installedTypeString = installedPackageVersion->GetMetadata()[PackageVersionMetadata::InstalledType];
switch (ConvertToInstallerTypeEnum(installedTypeString))
{
Expand Down Expand Up @@ -290,7 +297,15 @@ namespace AppInstaller::CLI::Workflow

void ExecuteUninstaller(Execution::Context& context)
{
const std::string installedTypeString = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata()[PackageVersionMetadata::InstalledType];
auto installedPackageVersion = context.Get<Execution::Data::InstalledPackageVersion>();

if (!installedPackageVersion)
{
AICLI_LOG(CLI, Verbose, << "No installed package version; cannot uninstall.");
return;
}

const std::string installedTypeString = installedPackageVersion->GetMetadata()[PackageVersionMetadata::InstalledType];
InstallerTypeEnum installerType = ConvertToInstallerTypeEnum(installedTypeString);

Synchronization::CrossProcessInstallLock lock;
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLIE2ETests/AppInstallerCLIE2ETests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<ItemGroup>
<None Remove="TestData\Configuration\ShowDetails_TestRepo_0_3.yml" />
<None Remove="TestData\Configuration\WithParameters_0_3.yml" />
<None Remove="TestData\Manifests\TestUpgradeAddsDependency.1.0.yaml" />
<None Remove="TestData\Manifests\TestUpgradeAddsDependency.2.0.yaml" />
<None Remove="TestData\Manifests\TestUpgradeAddsDependencyDependent.1.0.yaml" />
<Content Include="..\..\doc\admx\DesktopAppInstaller.admx" Link="TestData\DesktopAppInstaller.admx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PackageIdentifier: AppInstallerTest.TestUpgradeAddsDependency
PackageVersion: 1.0
PackageName: TestUpgradeAddsDependency
PackageLocale: en-US
Publisher: Microsoft
License: Test
ShortDescription: E2E test for adding a new package dependency during an upgrade.
Installers:
- Architecture: x86
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
InstallerType: exe
InstallerSha256: <EXEHASH>
ProductCode: '{fda6c0e2-0977-482f-bda1-9bd025457b81}'
InstallerSwitches:
Custom: '/ProductID {fda6c0e2-0977-482f-bda1-9bd025457b81}'
InstallLocation: /InstallDir <INSTALLPATH>
ManifestType: singleton
ManifestVersion: 1.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PackageIdentifier: AppInstallerTest.TestUpgradeAddsDependency
PackageVersion: 2.0
PackageName: TestUpgradeAddsDependency
PackageLocale: en-US
Publisher: Microsoft
License: Test
ShortDescription: E2E test for adding a new package dependency during an upgrade.
Installers:
- Architecture: x86
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
InstallerType: exe
InstallerSha256: <EXEHASH>
ProductCode: '{fda6c0e2-0977-482f-bda1-9bd025457b81}'
InstallerSwitches:
Custom: '/ProductID {fda6c0e2-0977-482f-bda1-9bd025457b81}'
InstallLocation: /InstallDir <INSTALLPATH>
Dependencies:
PackageDependencies:
- PackageIdentifier: AppInstallerTest.TestUpgradeAddsDependencyDependent
ManifestType: singleton
ManifestVersion: 1.4.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PackageIdentifier: AppInstallerTest.TestUpgradeAddsDependencyDependent
PackageVersion: 1.0
PackageName: TestUpgradeAddsDependencyDependent
PackageLocale: en-US
Publisher: Microsoft
License: Test
ShortDescription: E2E test for adding a new package dependency during an upgrade.
Installers:
- Architecture: x86
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
InstallerType: exe
InstallerSha256: <EXEHASH>
UpgradeBehavior: uninstallPrevious
ProductCode: '{648274a3-17aa-4731-8bf1-5854ca61e475}'
InstallerSwitches:
Custom: '/ProductID {648274a3-17aa-4731-8bf1-5854ca61e475}'
InstallLocation: /InstallDir <INSTALLPATH>
ManifestType: singleton
ManifestVersion: 1.4.0
13 changes: 13 additions & 0 deletions src/AppInstallerCLIE2ETests/UpgradeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,18 @@ public void UpgradeZip_Portable()
Assert.True(result2.StdOut.Contains("Successfully installed"));
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true, TestCommon.Scope.User);
}

/// <summary>
/// Test upgrade when a new dependency is added that is not installed.
/// </summary>
[Test]
public void UpgradeAddsDependency()
{
var result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestUpgradeAddsDependency -v 1.0 --verbose");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);

result = TestCommon.RunAICLICommand("upgrade", $"AppInstallerTest.TestUpgradeAddsDependency");
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
}
}
}

0 comments on commit 32e3bf9

Please sign in to comment.