commit 6813f335ccf9573335743a986d3bea573189360c
parent 3ffb45c2c97c6bdb96ee5fb8a98eb7417fb9f71e
Author: Chacón <lechacon@users.noreply.github.com>
Date: Thu, 23 Sep 2021 17:16:09 -0700
Ensure available packages match with a single installed package (#1473)
Diffstat:
3 files changed, 36 insertions(+), 11 deletions(-)
diff --git 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<Execution::Data::PackagesToInstall>())
+ if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies))
{
- if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies))
+ DependencyList allDependencies;
+ for (auto package : context.Get<Execution::Data::PackagesToInstall>())
{
allDependencies.Add(package.Installer.Dependencies);
}
- }
- if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies))
- {
context.Add<Execution::Data::Dependencies>(allDependencies);
context << Workflow::ReportDependencies(m_dependenciesReportMessage);
}
diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.h b/src/AppInstallerCLICore/Workflows/WorkflowBase.h
@@ -203,7 +203,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
@@ -623,14 +623,42 @@ namespace AppInstaller::Repository
// Correlate against installed (allow exceptions out as we own the installed source)
SearchResult installedCrossRef = m_installedSource->Search(systemReferenceSearch);
- for (auto&& crossRef : installedCrossRef.Matches)
+ std::shared_ptr<IPackage> 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<CompositePackage>(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<CompositePackage>(std::move(installedPackage), std::move(match.Package)), match.MatchCriteria);
+ }
}
// If there was no correlation for this package, add it without one.