BPackageManager: Add alternate Install()/Uninstall()/Update()

This commit is contained in:
Ingo Weinhold
2013-09-10 19:14:20 +02:00
parent 5a5d146510
commit 7e0d2c4f94
2 changed files with 39 additions and 21 deletions
@@ -77,10 +77,16 @@ public:
void Install(const char* const* packages,
int packageCount);
void Install(const BSolverPackageSpecifierList&
packages);
void Uninstall(const char* const* packages,
int packageCount);
void Uninstall(const BSolverPackageSpecifierList&
packages);
void Update(const char* const* packages,
int packageCount);
void Update(const BSolverPackageSpecifierList&
packages);
protected:
InstalledRepository& InstallationRepository();
+33 -21
View File
@@ -123,19 +123,23 @@ BPackageManager::Init(uint32 flags)
void
BPackageManager::Install(const char* const* packages, int packageCount)
{
BSolverPackageSpecifierList packagesToInstall;
if (!packagesToInstall.AppendSpecifiers(packages, packageCount))
throw std::bad_alloc();
Install(packagesToInstall);
}
void
BPackageManager::Install(const BSolverPackageSpecifierList& packages)
{
Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES
| B_REFRESH_REPOSITORIES);
// solve
BSolverPackageSpecifierList packagesToInstall;
for (int i = 0; i < packageCount; i++) {
if (!packagesToInstall.AppendSpecifier(packages[i]))
throw std::bad_alloc();
}
const BSolverPackageSpecifier* unmatchedSpecifier;
status_t error = fSolver->Install(packagesToInstall, &unmatchedSpecifier);
status_t error = fSolver->Install(packages, &unmatchedSpecifier);
if (error != B_OK) {
if (unmatchedSpecifier != NULL) {
DIE(error, "failed to find a match for \"%s\"",
@@ -155,19 +159,23 @@ BPackageManager::Install(const char* const* packages, int packageCount)
void
BPackageManager::Uninstall(const char* const* packages, int packageCount)
{
BSolverPackageSpecifierList packagesToUninstall;
if (!packagesToUninstall.AppendSpecifiers(packages, packageCount))
throw std::bad_alloc();
Uninstall(packagesToUninstall);
}
void
BPackageManager::Uninstall(const BSolverPackageSpecifierList& packages)
{
Init(B_ADD_INSTALLED_REPOSITORIES);
// find the packages that match the specification
BSolverPackageSpecifierList packagesToUninstall;
for (int i = 0; i < packageCount; i++) {
if (!packagesToUninstall.AppendSpecifier(packages[i]))
throw std::bad_alloc();
}
const BSolverPackageSpecifier* unmatchedSpecifier;
PackageList foundPackages;
status_t error = fSolver->FindPackages(packagesToUninstall,
status_t error = fSolver->FindPackages(packages,
BSolver::B_FIND_INSTALLED_ONLY, foundPackages, &unmatchedSpecifier);
if (error != B_OK) {
if (unmatchedSpecifier != NULL) {
@@ -243,19 +251,23 @@ BPackageManager::Uninstall(const char* const* packages, int packageCount)
void
BPackageManager::Update(const char* const* packages, int packageCount)
{
BSolverPackageSpecifierList packagesToUpdate;
if (!packagesToUpdate.AppendSpecifiers(packages, packageCount))
throw std::bad_alloc();
Update(packagesToUpdate);
}
void
BPackageManager::Update(const BSolverPackageSpecifierList& packages)
{
Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES
| B_REFRESH_REPOSITORIES);
// solve
BSolverPackageSpecifierList packagesToUpdate;
for (int i = 0; i < packageCount; i++) {
if (!packagesToUpdate.AppendSpecifier(packages[i]))
throw std::bad_alloc();
}
const BSolverPackageSpecifier* unmatchedSpecifier;
status_t error = fSolver->Update(packagesToUpdate, true,
status_t error = fSolver->Update(packages, true,
&unmatchedSpecifier);
if (error != B_OK) {
if (unmatchedSpecifier != NULL) {