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

Avoid creating installer node with duplicate NestedInstallerFile #419

Merged
merged 2 commits into from
Aug 8, 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
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