BSolver: Extend FindPackages() functionality
* Add flag B_FIND_INSTALLED_ONLY to only return installed packages. * Add FindPackages() version that finds packages like Install() or Uninstall() do.
This commit is contained in:
parent
220b5e1f29
commit
75d15eb4c2
@ -30,7 +30,8 @@ public:
|
||||
B_FIND_IN_NAME = 0x02,
|
||||
B_FIND_IN_SUMMARY = 0x04,
|
||||
B_FIND_IN_DESCRIPTION = 0x08,
|
||||
B_FIND_IN_PROVIDES = 0x10
|
||||
B_FIND_IN_PROVIDES = 0x10,
|
||||
B_FIND_INSTALLED_ONLY = 0x20,
|
||||
};
|
||||
|
||||
public:
|
||||
@ -46,6 +47,12 @@ public:
|
||||
virtual status_t FindPackages(const char* searchString,
|
||||
uint32 flags,
|
||||
BObjectList<BSolverPackage>& _packages) = 0;
|
||||
virtual status_t FindPackages(
|
||||
const BSolverPackageSpecifierList& packages,
|
||||
uint32 flags,
|
||||
BObjectList<BSolverPackage>& _packages,
|
||||
const BSolverPackageSpecifier** _unmatched
|
||||
= NULL) = 0;
|
||||
|
||||
virtual status_t Install(
|
||||
const BSolverPackageSpecifierList& packages,
|
||||
|
@ -300,21 +300,37 @@ LibsolvSolver::FindPackages(const char* searchString, uint32 flags,
|
||||
queue_push2(&selection, SOLVER_SOLVABLE, iterator.solvid);
|
||||
}
|
||||
|
||||
// get solvables
|
||||
SolvQueue solvables;
|
||||
selection_solvables(fPool, &selection, &solvables);
|
||||
|
||||
// get packages
|
||||
for (int i = 0; i < solvables.count; i++) {
|
||||
BSolverPackage* package = _GetPackage(solvables.elements[i]);
|
||||
if (package == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
if (!_packages.AddItem(package))
|
||||
return B_NO_MEMORY;
|
||||
return _GetFoundPackages(selection, flags, _packages);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
|
||||
status_t
|
||||
LibsolvSolver::FindPackages(const BSolverPackageSpecifierList& packages,
|
||||
uint32 flags, BObjectList<BSolverPackage>& _packages,
|
||||
const BSolverPackageSpecifier** _unmatched)
|
||||
{
|
||||
if (_unmatched != NULL)
|
||||
*_unmatched = NULL;
|
||||
|
||||
if ((flags & B_FIND_INSTALLED_ONLY) != 0 && fInstalledRepository == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// add repositories to pool
|
||||
status_t error = _AddRepositories();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
error = _InitJobQueue();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
// add the package specifies to the job queue
|
||||
error = _AddSpecifiedPackages(packages, _unmatched,
|
||||
(flags & B_FIND_INSTALLED_ONLY) != 0 ? SELECTION_INSTALLED_ONLY : 0);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
return _GetFoundPackages(*fJobs, flags, _packages);
|
||||
}
|
||||
|
||||
|
||||
@ -1252,6 +1268,35 @@ LibsolvSolver::_GetResolvableExpression(Id id,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LibsolvSolver::_GetFoundPackages(SolvQueue& selection, uint32 flags,
|
||||
BObjectList<BSolverPackage>& _packages)
|
||||
{
|
||||
// get solvables
|
||||
SolvQueue solvables;
|
||||
selection_solvables(fPool, &selection, &solvables);
|
||||
|
||||
// get packages
|
||||
for (int i = 0; i < solvables.count; i++) {
|
||||
BSolverPackage* package = _GetPackage(solvables.elements[i]);
|
||||
if (package == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
// TODO: Fix handling of SELECTION_INSTALLED_ONLY in libsolv. Despite
|
||||
// passing the flag, we get solvables that aren't installed.
|
||||
if ((flags & B_FIND_INSTALLED_ONLY) != 0
|
||||
&& package->Repository() != fInstalledRepository->Repository()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_packages.AddItem(package))
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LibsolvSolver::_Solve()
|
||||
{
|
||||
|
@ -37,6 +37,12 @@ public:
|
||||
virtual status_t FindPackages(const char* searchString,
|
||||
uint32 flags,
|
||||
BObjectList<BSolverPackage>& _packages);
|
||||
virtual status_t FindPackages(
|
||||
const BSolverPackageSpecifierList& packages,
|
||||
uint32 flags,
|
||||
BObjectList<BSolverPackage>& _packages,
|
||||
const BSolverPackageSpecifier** _unmatched
|
||||
= NULL);
|
||||
|
||||
virtual status_t Install(
|
||||
const BSolverPackageSpecifierList& packages,
|
||||
@ -108,6 +114,10 @@ private:
|
||||
BPackageResolvableExpression& _expression)
|
||||
const;
|
||||
|
||||
status_t _GetFoundPackages(SolvQueue& selection,
|
||||
uint32 flags,
|
||||
BObjectList<BSolverPackage>& _packages);
|
||||
|
||||
status_t _Solve();
|
||||
void _SetJobsSolverMode(int solverMode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user