commit b6678600b294cfb1ac5b74524b914daf23845103 parent 9022873180fe533c71746da7e7bbf46b3e9cc6ee Author: JohnMcPMS <johnmcp@microsoft.com> Date: Tue, 12 Apr 2022 15:27:04 -0700 Fix issue with correlation chaining from the SQLite index (#2087) The composite source correlation was using the name + publisher values in a very optimistic way, which was leading to the potential for some values to get lost. This change creates a search on the cartesian product of the values, which is more expensive but also more correct. Diffstat:
4 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/src/AppInstallerRepositoryCore/CompositeSource.cpp b/src/AppInstallerRepositoryCore/CompositeSource.cpp @@ -607,15 +607,21 @@ namespace AppInstaller::Repository IPackageVersion* installedVersion, PackageData& data) { + // Unfortunately the names and publishers are unique and not tied to each other strictly, so we need + // to go broad on the matches. Future work can hopefully make name and publisher operate more as a unit, + // but for now we have to search for the cartesian of these... auto names = installedVersion->GetMultiProperty(PackageVersionMultiProperty::Name); auto publishers = installedVersion->GetMultiProperty(PackageVersionMultiProperty::Publisher); - for (size_t i = 0; i < names.size() && i < publishers.size(); ++i) + for (size_t i = 0; i < names.size(); ++i) { - data.AddIfNotPresent(SystemReferenceString{ - PackageMatchField::NormalizedNameAndPublisher, - std::move(names[i]), - std::move(publishers[i]) }); + for (size_t j = 0; j < publishers.size(); ++j) + { + data.AddIfNotPresent(SystemReferenceString{ + PackageMatchField::NormalizedNameAndPublisher, + names[i], + publishers[j] }); + } } } }; diff --git a/src/AppInstallerRepositoryCore/Public/winget/RepositorySearch.h b/src/AppInstallerRepositoryCore/Public/winget/RepositorySearch.h @@ -145,11 +145,12 @@ namespace AppInstaller::Repository // The product codes associated with the package version. ProductCode, // TODO: Fully implement these 3; the data is not yet in the index source (name and publisher are hacks and locale is not present) - // The package names for the version; these must match in number and order with both Publisher and Locale. + // For future usage of these, be aware of the limitations. + // The package names for the version; ideally these would match in number and order with both Publisher and Locale. Name, - // The publisher values for the version; these must match in number and order with both Name and Locale. + // The publisher values for the version; ideally these would match in number and order with both Name and Locale. Publisher, - // The locale of the matching Name and Publisher values; these must match in number and order with both Name and Publisher. + // The locale of the matching Name and Publisher values; ideally these would match in number and order with both Name and Publisher. // May be empty if there is only a single value for Name and Publisher. Locale, }; diff --git a/tools/CorrelationTestbed/InstallAndCheckCorrelation/InstallAndCheckCorrelation/InstallAndCheckCorrelation.cpp b/tools/CorrelationTestbed/InstallAndCheckCorrelation/InstallAndCheckCorrelation/InstallAndCheckCorrelation.cpp @@ -128,6 +128,7 @@ struct Main std::string sourceName; std::filesystem::path outputPath; bool useDevCLSIDs = false; + bool onlyCorrelate = false; int ParseArgs(int argc, char** argv) { @@ -136,6 +137,7 @@ struct Main // -src : [Required] The source name for the package to install // -out : [Required] The file to write results to // -dev : [Optional] Use the dev CLSIDs + // -cor : [Optional] Only correlate the package for (int i = 1; i < argc; ++i) { @@ -155,6 +157,10 @@ struct Main { useDevCLSIDs = true; } + else if ("-cor"sv == argv[i]) + { + onlyCorrelate = true; + } } // Check inputs @@ -324,20 +330,23 @@ struct Main packagePublisher = ConvertToUTF8(installVersion.Publisher()); } - action = "Create install options"; - auto installOptions = CreateInstallOptions(); + if (!onlyCorrelate) + { + action = "Create install options"; + auto installOptions = CreateInstallOptions(); - installOptions.PackageInstallScope(PackageInstallScope::Any); - installOptions.PackageInstallMode(PackageInstallMode::Silent); + installOptions.PackageInstallScope(PackageInstallScope::Any); + installOptions.PackageInstallMode(PackageInstallMode::Silent); - std::cout << "Beginning to install " << packageIdentifier << " (" << packageName << ") from " << sourceName << "..." << std::endl; - auto installResult = packageManager.InstallPackageAsync(package, installOptions).get(); + std::cout << "Beginning to install " << packageIdentifier << " (" << packageName << ") from " << sourceName << "..." << std::endl; + auto installResult = packageManager.InstallPackageAsync(package, installOptions).get(); - if (installResult.Status() != InstallResultStatus::Ok) - { - hr = installResult.ExtendedErrorCode(); - error = "Error installing package"; - return; + if (installResult.Status() != InstallResultStatus::Ok) + { + hr = installResult.ExtendedErrorCode(); + error = "Error installing package"; + return; + } } } catch (const winrt::hresult_error& hre) diff --git a/tools/CorrelationTestbed/InstallAndCheckCorrelation/InstallAndCheckCorrelation/Microsoft.Management.Deployment.winmd b/tools/CorrelationTestbed/InstallAndCheckCorrelation/InstallAndCheckCorrelation/Microsoft.Management.Deployment.winmd Binary files differ.