diff --git a/src/AppInstallerCLICore/Workflows/InstallFlow.cpp b/src/AppInstallerCLICore/Workflows/InstallFlow.cpp index 8f6b17964a..b6ca2db78a 100644 --- a/src/AppInstallerCLICore/Workflows/InstallFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/InstallFlow.cpp @@ -641,17 +641,14 @@ namespace AppInstaller::CLI::Workflow } // Report dependencies - DependencyList allDependencies; - for (auto package : context.Get()) + if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies)) { - if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies)) + DependencyList allDependencies; + for (auto package : context.Get()) { allDependencies.Add(package.Installer.Dependencies); } - } - if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies)) - { context.Add(allDependencies); context << Workflow::ReportDependencies(m_dependenciesReportMessage); } diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.h b/src/AppInstallerCLICore/Workflows/WorkflowBase.h index 2a7a976964..a78170f27d 100644 --- a/src/AppInstallerCLICore/Workflows/WorkflowBase.h +++ b/src/AppInstallerCLICore/Workflows/WorkflowBase.h @@ -194,7 +194,7 @@ namespace AppInstaller::CLI::Workflow // Ensures that there is only one result in the search. // Required Args: bool indicating if the search result is from installed source // Inputs: SearchResult - // Outputs: None + // Outputs: Package struct EnsureOneMatchFromSearchResult : public WorkflowTask { EnsureOneMatchFromSearchResult(bool isFromInstalledSource) : diff --git a/src/AppInstallerRepositoryCore/CompositeSource.cpp b/src/AppInstallerRepositoryCore/CompositeSource.cpp index 21ec7c1a9a..35412d39b8 100644 --- a/src/AppInstallerRepositoryCore/CompositeSource.cpp +++ b/src/AppInstallerRepositoryCore/CompositeSource.cpp @@ -553,14 +553,42 @@ namespace AppInstaller::Repository SearchResult installedCrossRef = m_installedSource->Search(systemReferenceSearch); - for (auto&& crossRef : installedCrossRef.Matches) + std::shared_ptr installedPackage; + if (installedCrossRef.Matches.size() == 1) { - if (!result.ContainsInstalledPackage(crossRef.Package.get())) + installedPackage = std::move(installedCrossRef.Matches[0].Package); + } + else if (installedCrossRef.Matches.size() > 1) + { + AICLI_LOG(Repo, Info, + << "Found multiple matches for available package [" << match.Package->GetProperty(PackageProperty::Id) << + "] in source [" << source->GetIdentifier() << "] when searching for [" << systemReferenceSearch.ToString() << "]"); + + // More than one match found for the system reference; run some heuristics to check for a match + for (auto&& crossRef : installedCrossRef.Matches) { - foundInstalledMatch = true; - result.Matches.emplace_back(std::make_shared(std::move(crossRef.Package), std::move(match.Package)), match.MatchCriteria); + AICLI_LOG(Repo, Info, << " Checking match with package id: " << crossRef.Package->GetProperty(PackageProperty::Id)); + if (IsStrongMatchField(crossRef.MatchCriteria.Field)) + { + if (!installedPackage) + { + installedPackage = std::move(crossRef.Package); + } + else + { + AICLI_LOG(Repo, Info, << " Found multiple packages with strong match fields"); + installedPackage.reset(); + break; + } + } } } + + if (installedPackage && !result.ContainsInstalledPackage(installedPackage.get())) + { + foundInstalledMatch = true; + result.Matches.emplace_back(std::make_shared(std::move(installedPackage), std::move(match.Package)), match.MatchCriteria); + } } // If there was no correlation for this package, add it without one.