diff --git a/headers/private/package/manager/PackageManager.h b/headers/private/package/manager/PackageManager.h index 9ef3c7a45a..b8ef231c63 100644 --- a/headers/private/package/manager/PackageManager.h +++ b/headers/private/package/manager/PackageManager.h @@ -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(); diff --git a/src/kits/package/manager/PackageManager.cpp b/src/kits/package/manager/PackageManager.cpp index e565a030f7..5e638cc1dc 100644 --- a/src/kits/package/manager/PackageManager.cpp +++ b/src/kits/package/manager/PackageManager.cpp @@ -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) {