Skip to content

Commit

Permalink
Ensure available packages match with a single installed package (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chacón authored Sep 24, 2021
1 parent 3ffb45c commit 6813f33
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/AppInstallerCLICore/Workflows/InstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/WorkflowBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
36 changes: 32 additions & 4 deletions src/AppInstallerRepositoryCore/CompositeSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6813f33

Please sign in to comment.