Skip to content

Commit

Permalink
Avoid creating installer node with duplicate NestedInstallerFile (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanish-kh authored Aug 8, 2023
1 parent ef2c2e7 commit 93473ef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/WingetCreateCore/Common/PackageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ private static bool ParsePackageAndGenerateInstallerNodes(InstallerMetadata inst

foreach (NestedInstallerFile nestedInstallerFile in installerMetadata.NestedInstallerFiles)
{
// Skip adding duplicate NestedInstallerFile object.
if (baseInstaller.NestedInstallerFiles.Any(i =>
i.RelativeFilePath == nestedInstallerFile.RelativeFilePath &&
i.PortableCommandAlias == nestedInstallerFile.PortableCommandAlias))
{
continue;
}

baseInstaller.NestedInstallerFiles.Add(new NestedInstallerFile
{
RelativeFilePath = nestedInstallerFile.RelativeFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ Installers:
NestedInstallerType: exe
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestPortableCommandAlias
- Architecture: x86
InstallerType: zip
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: exe
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestPortableCommandAlias
- Architecture: arm64
InstallerType: zip
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: exe
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestPortableCommandAlias
PackageLocale: en-US
ManifestType: singleton
ManifestVersion: 1.4.0
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,44 @@ public async Task UpdateZipWithMsix()
Assert.IsTrue(initialSecondInstaller.InstallerSha256 != updatedSecondInstaller.InstallerSha256, "InstallerSha256 should be updated");
}

/// <summary>
/// Verifies that updating a zip package with multiple zip installers works as expected.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Test]
public async Task UpdateMultipleZipInstallers()
{
TestUtils.InitializeMockDownloads(TestConstants.TestZipInstaller);

string installerUrl = $"https://fakedomain.com/{TestConstants.TestZipInstaller}";
(UpdateCommand command, var initialManifestContent) = GetUpdateCommandAndManifestData("TestPublisher.ZipMultipleInstallers", null, this.tempPath, new[] { $"{installerUrl}|x64", $"{installerUrl}|x86", $"{installerUrl}|arm64" });

var updatedManifests = await RunUpdateCommand(command, initialManifestContent);
Assert.IsNotNull(updatedManifests, "Command should have succeeded");

var initialManifests = Serialization.DeserializeManifestContents(initialManifestContent);
var initialInstallers = initialManifests.SingletonManifest.Installers;
var initialFirstInstaller = initialInstallers[0];
var initialSecondInstaller = initialInstallers[1];
var initialThirdInstaller = initialInstallers[2];

var updatedInstallerManifest = updatedManifests.InstallerManifest;
var updatedFirstInstaller = updatedInstallerManifest.Installers[0];
var updatedSecondInstaller = updatedInstallerManifest.Installers[1];
var updatedThirdInstaller = updatedInstallerManifest.Installers[2];

Assert.IsTrue(updatedInstallerManifest.InstallerType == InstallerType.Zip, "InstallerType should be ZIP");
Assert.IsTrue(updatedInstallerManifest.NestedInstallerType == NestedInstallerType.Exe, "NestedInstallerType should be EXE");
Assert.IsTrue(updatedInstallerManifest.NestedInstallerFiles.Count == 1, "NestedInstallerFiles list should contain only one member");

Assert.IsTrue(initialFirstInstaller.NestedInstallerFiles[0].RelativeFilePath == updatedInstallerManifest.NestedInstallerFiles[0].RelativeFilePath, "RelativeFilePath should be preserved.");
Assert.IsTrue(initialFirstInstaller.NestedInstallerFiles[0].PortableCommandAlias == updatedInstallerManifest.NestedInstallerFiles[0].PortableCommandAlias, "PortableCommandAlias should be preserved.");

Assert.IsTrue(initialFirstInstaller.InstallerSha256 != updatedFirstInstaller.InstallerSha256, "InstallerSha256 should be updated");
Assert.IsTrue(initialSecondInstaller.InstallerSha256 != updatedSecondInstaller.InstallerSha256, "InstallerSha256 should be updated");
Assert.IsTrue(initialThirdInstaller.InstallerSha256 != updatedThirdInstaller.InstallerSha256, "InstallerSha256 should be updated");
}

/// <summary>
/// Verifies that moving common installer fields to the root of the manifest works as expected.
/// </summary>
Expand Down

0 comments on commit 93473ef

Please sign in to comment.