void BPackageManager::Uninstall(const char* const* packages, int packageCount) { BSolverPackageSpecifierList packagesToUninstall; if (!packagesToUninstall.AppendSpecifiers(packages, packageCount)) throw std::bad_alloc(); Uninstall(packagesToUninstall); }
void BPackageManager::_AddPackageSpecifiers(const char* const* searchStrings, int searchStringCount, BSolverPackageSpecifierList& specifierList) { for (int i = 0; i < searchStringCount; i++) { const char* searchString = searchStrings[i]; if (_IsLocalPackage(searchString)) { BSolverPackage* package = _AddLocalPackage(searchString); if (!specifierList.AppendSpecifier(package)) throw std::bad_alloc(); } else { if (!specifierList.AppendSpecifier(searchString)) throw std::bad_alloc(); } } }
int InstallCommand::Execute(int argc, const char* const* argv) { BPackageInstallationLocation location = B_PACKAGE_INSTALLATION_LOCATION_SYSTEM; bool interactive = true; while (true) { static struct option sLongOptions[] = { { "debug", required_argument, 0, OPTION_DEBUG }, { "help", no_argument, 0, 'h' }, { "home", no_argument, 0, 'H' }, { 0, 0, 0, 0 } }; opterr = 0; // don't print errors int c = getopt_long(argc, (char**)argv, "hHy", sLongOptions, NULL); if (c == -1) break; if (fCommonOptions.HandleOption(c)) continue; switch (c) { case 'h': PrintUsageAndExit(false); break; case 'H': location = B_PACKAGE_INSTALLATION_LOCATION_HOME; break; case 'y': interactive = false; break; default: PrintUsageAndExit(true); break; } } // The remaining arguments are the packages to be installed. if (argc < optind + 1) PrintUsageAndExit(true); int packageCount = argc - optind; const char* const* packages = argv + optind; // perform the installation PackageManager packageManager(location, interactive); packageManager.SetDebugLevel(fCommonOptions.DebugLevel()); try { packageManager.Install(packages, packageCount); } catch (BNothingToDoException&) { // Output already installed packages BSolverPackageSpecifierList packagesToInstall; if (!packagesToInstall.AppendSpecifiers(packages, packageCount)) throw std::bad_alloc(); // Find the installed packages that match the specification const BSolverPackageSpecifier* unmatchedSpecifier; BObjectList<BSolverPackage> installedPackages; packageManager.Solver()->FindPackages(packagesToInstall, BSolver::B_FIND_INSTALLED_ONLY, installedPackages, &unmatchedSpecifier); for (int32 i = 0; BSolverPackage* package = installedPackages.ItemAt(i); i++) { BString repository; if (dynamic_cast<PackageManager::MiscLocalRepository*>( package->Repository()) != NULL) repository = "local file"; else repository.SetToFormat( "repository %s", package->Repository()->Name().String()); fprintf(stderr, "%s from %s is already installed.\n", package->VersionedName().String(), repository.String()); } throw; } return 0; }
void PackageManager::HandleUserChanges() { const PackageSet& packagesToActivate = fVolume->PackagesToBeActivated(); const PackageSet& packagesToDeactivate = fVolume->PackagesToBeDeactivated(); if (packagesToActivate.empty() && packagesToDeactivate.empty()) return; if (packagesToActivate.empty()) { // only packages removed -- use uninstall mode Init(B_ADD_INSTALLED_REPOSITORIES); BSolverPackageSpecifierList packagesToUninstall; for (PackageSet::const_iterator it = packagesToDeactivate.begin(); it != packagesToDeactivate.end(); ++it) { BSolverPackage* solverPackage = _SolverPackageFor(*it); if (solverPackage == NULL) continue; if (!packagesToUninstall.AppendSpecifier(solverPackage)) throw std::bad_alloc(); fPackagesRemovedByUser.insert(solverPackage); } if (fPackagesRemovedByUser.empty()) return; Uninstall(packagesToUninstall); } else { // packages added and (possibly) remove -- manually add/remove those // from the repository and use verify mode Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES | B_REFRESH_REPOSITORIES); // disable and remove uninstalled packages InstalledRepository& repository = InstallationRepository(); for (PackageSet::const_iterator it = packagesToDeactivate.begin(); it != packagesToDeactivate.end(); ++it) { BSolverPackage* solverPackage = _SolverPackageFor(*it); if (solverPackage == NULL) continue; repository.DisablePackage(solverPackage); if (!repository.PackagesToDeactivate().AddItem(solverPackage)) throw std::bad_alloc(); fPackagesRemovedByUser.insert(solverPackage); } // add new packages BRepositoryBuilder repositoryBuilder(repository); for (PackageSet::const_iterator it = packagesToActivate.begin(); it != packagesToActivate.end(); ++it) { Package* package = *it; BSolverPackage* solverPackage; repositoryBuilder.AddPackage(package->Info(), NULL, &solverPackage); fSolverPackages[package] = solverPackage; if (!repository.PackagesToActivate().AddItem(solverPackage)) throw std::bad_alloc(); fPackagesAddedByUser.insert(solverPackage); } if (fPackagesRemovedByUser.empty() && fPackagesAddedByUser.empty()) return; // TODO: When packages are moved out of the packages directory, we can't create // a complete "old-state" directory. VerifyInstallation(); } }