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

Improve matching for ZIP with multiple nested installers #529

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions src/WingetCreateCore/Common/PackageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public static void UpdateInstallerNodesAsync(List<InstallerMetadata> installerMe
{
parseFailedInstallerUrls.Add(installerMetadata.InstallerUrl);
}

// In case of multiple nested installers in the archive, we expect the new installers to have duplicates
// Remove these duplicates to avoid multiple matches.
installerMetadata.NewInstallers = installerMetadata.NewInstallers.Distinct().ToList();
}

int numOfNewInstallers = installerMetadataList.Sum(x => x.NewInstallers.Count);
Expand Down Expand Up @@ -249,6 +253,24 @@ public static void UpdateInstallerNodesAsync(List<InstallerMetadata> installerMe
// If a match is found, add match to dictionary and remove for list of existingInstallers
if (existingInstallerMatch != null)
{
// Remove the nested installers from the new installer that are not present in the existing installer.
if (newInstaller.NestedInstallerFiles != null && existingInstallerMatch.NestedInstallerFiles != null)
{
var matchedFiles = newInstaller.NestedInstallerFiles
.Where(nif =>
{
var fileName = Path.GetFileName(nif.RelativeFilePath);

// If the flow reaches here, there's guaranteed to be a matching file name
// Any mismatches would've been detected earlier in the update flow.
return existingInstallerMatch.NestedInstallerFiles.Any(eif =>
Path.GetFileName(eif.RelativeFilePath) == fileName);
})
.ToList();

newInstaller.NestedInstallerFiles = matchedFiles;
}

installerMatchDict.Add(existingInstallerMatch, newInstaller);
existingInstallers.Remove(existingInstallerMatch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ Description: |-

1) For the first installer, all root level fields are copied over and root fields are set to null.
2) For the second installer, installer level fields are preserved since they are not null.
3) InstallerType and NestedInstallerType are common across both installers, so they are moved to the root level at the end of the update.

TODO: Use different NestedInstallerType and RelativeFilePath for each installer once logic for handling multiple nested installers is improved.
Reference: https://github.com/microsoft/winget-create/issues/392
3) InstallerType is common across both installers, so it is moved to the root level at the end of the update.
InstallerLocale: en-US
InstallerType: zip
NestedInstallerType: exe
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestAlias
PortableCommandAlias: TestExeAlias
AppsAndFeaturesEntries:
- DisplayName: TestDisplayName1
Publisher: TestPublisher1
Expand Down Expand Up @@ -87,10 +84,10 @@ Installers:
InstallerType: zip
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: exe
NestedInstallerType: msi
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestAlias
- RelativeFilePath: WingetCreateTestMsiInstaller.msi
PortableCommandAlias: TestMsiAlias
AppsAndFeaturesEntries:
- DisplayName: TestDisplayName2
Publisher: TestPublisher2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
PackageIdentifier: TestPublisher.MultipleNestedInstallers
PackageVersion: 0.1.2
PackageName: Test zip app
Publisher: Test publisher
License: MIT
ShortDescription: A manifest used for testing whether multiple nested installers are handled correctly.
Description: The zip archive contains extra nested installers that are intentionally left out in the manifest to test the behavior.
Installers:
- Architecture: x64
InstallerType: zip
InstallerUrl: https://fakedomain.com/WingetCreateTestMultipleNestedInstallers.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: portable
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestExeInstallerAlias
- RelativeFilePath: WingetCreateTestPortable.exe
PortableCommandAlias: TestPortableCommandAlias
- RelativeFilePath: WingetCreateTestPortable2.exe
PortableCommandAlias: TestPortableCommandAlias2
- RelativeFilePath: WingetCreateTestPortable3.exe
PortableCommandAlias: TestPortableCommandAlias3
- Architecture: x86
InstallerType: zip
InstallerUrl: https://fakedomain.com/WingetCreateTestMultipleNestedInstallers.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: portable
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestPortable.exe
PortableCommandAlias: TestPortableCommandAlias
- RelativeFilePath: WingetCreateTestPortable2.exe
PortableCommandAlias: TestPortableCommandAlias2
- Architecture: arm
InstallerType: zip
InstallerUrl: https://fakedomain.com/WingetCreateTestMultipleNestedInstallers.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: portable
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestPortable3.exe
PortableCommandAlias: TestPortableCommandAlias3
- Architecture: arm64
InstallerType: zip
Scope: user
InstallerUrl: https://fakedomain.com/WingetCreateTestMultipleNestedInstallers.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: exe
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestExeInstaller.exe
PortableCommandAlias: TestExeInstallerAlias
- Architecture: arm64
InstallerType: zip
Scope: machine
InstallerUrl: https://fakedomain.com/WingetCreateTestMultipleNestedInstallers.zip
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
NestedInstallerType: msi
NestedInstallerFiles:
- RelativeFilePath: WingetCreateTestMsiInstaller.msi
PortableCommandAlias: TestMsiInstallerAlias
PackageLocale: en-US
ManifestType: singleton
ManifestVersion: 1.6.0
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions src/WingetCreateTests/WingetCreateTests/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public static class TestConstants
/// </summary>
public const string TestZipInstaller = "WingetCreateTestZipInstaller.zip";

/// <summary>
/// File name of the archive containing multiple installers.
/// </summary>
public const string TestZipMultipleNestedInstallers = "WingetCreateTestMultipleNestedInstallers.zip";

/// <summary>
/// Format argument to be used for YAML submissions.
/// </summary>
Expand Down
Loading