status_t RepositoriesSettings::GetRepositories(int32& repoCount, BStringList& nameList, BStringList& urlList) { BMessage settings(_ReadFromFile()); type_code type; int32 count; settings.GetInfo(key_name, &type, &count); status_t result = B_OK; int32 index, total = 0; BString foundName, foundUrl; // get each repository and add to lists for (index = 0; index < count; index++) { status_t result1 = settings.FindString(key_name, index, &foundName); status_t result2 = settings.FindString(key_url, index, &foundUrl); if (result1 == B_OK && result2 == B_OK) { nameList.Add(foundName); urlList.Add(foundUrl); total++; } else result = B_ERROR; } repoCount = total; return result; }
/*static*/ status_t BPathFinder::FindPaths(const char* architecture, path_base_directory baseDirectory, const char* subPath, uint32 flags, BStringList& _paths) { _paths.MakeEmpty(); // get the paths char** pathArray; size_t pathCount; status_t error = find_paths_etc(architecture, baseDirectory, subPath, flags, &pathArray, &pathCount); if (error != B_OK) return error; MemoryDeleter pathArrayDeleter(pathArray); // add them to BStringList for (size_t i = 0; i < pathCount; i++) { BString path(pathArray[i]); if (path.IsEmpty() || !_paths.Add(path)) { _paths.MakeEmpty(); return B_NO_MEMORY; } } return B_OK; }
void PackageManager::_PrintResult(InstalledRepository& installationRepository) { if (!installationRepository.HasChanges()) return; printf(" in %s:\n", installationRepository.Name().String()); PackageList& packagesToActivate = installationRepository.PackagesToActivate(); PackageList& packagesToDeactivate = installationRepository.PackagesToDeactivate(); BStringList upgradedPackages; for (int32 i = 0; BSolverPackage* installPackage = packagesToActivate.ItemAt(i); i++) { for (int32 j = 0; BSolverPackage* uninstallPackage = packagesToDeactivate.ItemAt(j); j++) { if (installPackage->Info().Name() == uninstallPackage->Info().Name()) { upgradedPackages.Add(installPackage->Info().Name()); break; } } } for (int32 i = 0; BSolverPackage* package = packagesToActivate.ItemAt(i); i++) { BString repository; if (dynamic_cast<MiscLocalRepository*>(package->Repository()) != NULL) repository = "local file"; else repository.SetToFormat("repository %s", package->Repository()->Name().String()); if (upgradedPackages.HasString(package->Info().Name())) { printf(" upgrade package %s to %s from %s\n", package->Info().Name().String(), package->Info().Version().ToString().String(), repository.String()); } else { printf(" install package %s-%s from %s\n", package->Info().Name().String(), package->Info().Version().ToString().String(), repository.String()); } } for (int32 i = 0; BSolverPackage* package = packagesToDeactivate.ItemAt(i); i++) { if (upgradedPackages.HasString(package->Info().Name())) continue; printf(" uninstall package %s\n", package->VersionedName().String()); } // TODO: Print file/download sizes. Unfortunately our package infos don't // contain the file size. Which is probably correct. The file size (and possibly // other information) should, however, be provided by the repository cache in // some way. Extend BPackageInfo? Create a BPackageFileInfo? }
void LaunchDaemon::_AddRunTargets(BMessage& message, const char* name) { BMessage targets; if (name != NULL && message.FindMessage(name, &targets) != B_OK) return; const char* target; for (int32 index = 0; targets.FindString("target", index, &target) == B_OK; index++) { fRunTargets.Add(target); } }
void POP3Protocol::CheckForDeletedMessages() { { // Delete things from the manifest no longer on the server BStringList list; NotHere(fUniqueIDs, fManifest, &list); fManifest.Remove(list); } if (!fSettings.FindBool("delete_remote_when_local") || fManifest.CountStrings() == 0) return; BStringList toDelete; BStringList queryContents; BVolumeRoster volumes; BVolume volume; while (volumes.GetNextVolume(&volume) == B_OK) { BQuery fido; entry_ref entry; fido.SetVolume(&volume); fido.PushAttr(B_MAIL_ATTR_ACCOUNT_ID); fido.PushInt32(fAccountSettings.AccountID()); fido.PushOp(B_EQ); fido.Fetch(); BString uid; while (fido.GetNextRef(&entry) == B_OK) { BNode(&entry).ReadAttrString("MAIL:unique_id", &uid); queryContents.Add(uid); } } NotHere(queryContents, fManifest, &toDelete); for (int32 i = 0; i < toDelete.CountStrings(); i++) { printf("delete mail on server uid %s\n", toDelete.StringAt(i).String()); Delete(fUniqueIDs.IndexOf(toDelete.StringAt(i))); } // Don't remove ids from fUniqueIDs, the indices have to stay the same when // retrieving new messages. fManifest.Remove(toDelete); // TODO: at some point the purged manifest should be written to disk // otherwise it will grow forever }
status_t operator()(const BEntry& entry) { char name[B_FILE_NAME_LENGTH]; status_t result = entry.GetName(name); if (result != B_OK) return result; int32 count = names.CountStrings(); for (int i = 0; i < count; ++i) { if (names.StringAt(i).Compare(name) == 0) return B_OK; } names.Add(name); return B_OK; }
void BaseJob::_ParseExportVariable(BStringList& environment, const BString& line) { if (!line.StartsWith("export ")) return; int separator = line.FindFirst("=\""); if (separator < 0) return; BString variable; line.CopyInto(variable, 7, separator - 7); BString value; line.CopyInto(value, separator + 2, line.Length() - separator - 3); variable << "=" << value; environment.Add(variable); }
thread_id TeamDebugHandler::_EnterDebugger(bool saveReport) { TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): team %" B_PRId32 "\n", fTeam)); // prepare a debugger handover TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): preparing " "debugger handover for team %" B_PRId32 "...\n", fTeam)); status_t error = send_debug_message(&fDebugContext, B_DEBUG_MESSAGE_PREPARE_HANDOVER, NULL, 0, NULL, 0); if (error != B_OK) { debug_printf("debug_server: Failed to prepare debugger handover: %s\n", strerror(error)); return error; } BStringList arguments; const char *argv[16]; int argc = 0; bool debugInConsoled = _IsGUIServer() || !_AreGUIServersAlive(); #ifdef HANDOVER_USE_GDB error = _SetupGDBArguments(arguments, debugInConsoled); if (error != B_OK) { debug_printf("debug_server: Failed to set up gdb arguments: %s\n", strerror(error)); return error; } // start the terminal TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): starting " "terminal (debugger) for team %" B_PRId32 "...\n", fTeam)); #elif defined(HANDOVER_USE_DEBUGGER) if (!debugInConsoled && !saveReport && be_roster->IsRunning(kDebuggerSignature)) { // for graphical handovers, check if Debugger is already running, // and if it is, simply send it a message to attach to the requested // team. BMessenger messenger(kDebuggerSignature); BMessage message(MSG_DEBUG_THIS_TEAM); if (message.AddInt32("team", fTeam) == B_OK && messenger.SendMessage(&message) == B_OK) { return 0; } } // prepare the argument vector BPath debuggerPath; if (debugInConsoled) { error = find_directory(B_SYSTEM_BIN_DIRECTORY, &debuggerPath); if (error != B_OK) { debug_printf("debug_server: can't find system-bin directory: %s\n", strerror(error)); return error; } error = debuggerPath.Append("consoled"); if (error != B_OK) { debug_printf("debug_server: can't append to system-bin path: %s\n", strerror(error)); return error; } if (!arguments.Add(debuggerPath.Path())) return B_NO_MEMORY; } error = find_directory(B_SYSTEM_APPS_DIRECTORY, &debuggerPath); if (error != B_OK) { debug_printf("debug_server: can't find system-apps directory: %s\n", strerror(error)); return error; } error = debuggerPath.Append("Debugger"); if (error != B_OK) { debug_printf("debug_server: can't append to system-apps path: %s\n", strerror(error)); return error; } if (!arguments.Add(debuggerPath.Path())) return B_NO_MEMORY; if (debugInConsoled && !arguments.Add("--cli")) return B_NO_MEMORY; BString debuggerParam; debuggerParam.SetToFormat("%" B_PRId32, fTeam); if (saveReport) { if (!arguments.Add("--save-report")) return B_NO_MEMORY; } if (!arguments.Add("--team") || !arguments.Add(debuggerParam)) return B_NO_MEMORY; // start the debugger TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): starting " "%s debugger for team %" B_PRId32 "...\n", debugInConsoled ? "command line" : "graphical", fTeam)); #endif for (int32 i = 0; i < arguments.CountStrings(); i++) argv[argc++] = arguments.StringAt(i).String(); argv[argc] = NULL; thread_id thread = load_image(argc, argv, (const char**)environ); if (thread < 0) { debug_printf("debug_server: Failed to start debugger: %s\n", strerror(thread)); return thread; } resume_thread(thread); TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): debugger started " "for team %" B_PRId32 ": thread: %" B_PRId32 "\n", fTeam, thread)); return thread; }
status_t TeamDebugHandler::_SetupGDBArguments(BStringList &arguments, bool usingConsoled) { // prepare the argument vector BString teamString; teamString.SetToFormat("--pid=%" B_PRId32, fTeam); status_t error; BPath terminalPath; if (usingConsoled) { error = find_directory(B_SYSTEM_BIN_DIRECTORY, &terminalPath); if (error != B_OK) { debug_printf("debug_server: can't find system-bin directory: %s\n", strerror(error)); return error; } error = terminalPath.Append("consoled"); if (error != B_OK) { debug_printf("debug_server: can't append to system-bin path: %s\n", strerror(error)); return error; } } else { error = find_directory(B_SYSTEM_APPS_DIRECTORY, &terminalPath); if (error != B_OK) { debug_printf("debug_server: can't find system-apps directory: %s\n", strerror(error)); return error; } error = terminalPath.Append("Terminal"); if (error != B_OK) { debug_printf("debug_server: can't append to system-apps path: %s\n", strerror(error)); return error; } } arguments.MakeEmpty(); if (!arguments.Add(terminalPath.Path())) return B_NO_MEMORY; if (!usingConsoled) { BString windowTitle; windowTitle.SetToFormat("Debug of Team %" B_PRId32 ": %s", fTeam, _LastPathComponent(fExecutablePath)); if (!arguments.Add("-t") || !arguments.Add(windowTitle)) return B_NO_MEMORY; } BPath gdbPath; error = find_directory(B_SYSTEM_BIN_DIRECTORY, &gdbPath); if (error != B_OK) { debug_printf("debug_server: can't find system-bin directory: %s\n", strerror(error)); return error; } error = gdbPath.Append("gdb"); if (error != B_OK) { debug_printf("debug_server: can't append to system-bin path: %s\n", strerror(error)); return error; } if (!arguments.Add(gdbPath.Path()) || !arguments.Add(teamString)) return B_NO_MEMORY; if (strlen(fExecutablePath) > 0 && !arguments.Add(fExecutablePath)) return B_NO_MEMORY; return B_OK; }
void MainWindow::_RefreshPackageList() { BPackageRoster roster; BStringList repositoryNames; status_t result = roster.GetRepositoryNames(repositoryNames); if (result != B_OK) return; DepotInfoMap depots; for (int32 i = 0; i < repositoryNames.CountStrings(); i++) { const BString& repoName = repositoryNames.StringAt(i); depots[repoName] = DepotInfo(repoName); } PackageManager manager(B_PACKAGE_INSTALLATION_LOCATION_HOME); try { manager.Init(PackageManager::B_ADD_INSTALLED_REPOSITORIES | PackageManager::B_ADD_REMOTE_REPOSITORIES); } catch (BException ex) { BString message(B_TRANSLATE("An error occurred while " "initializing the package manager: %message%")); message.ReplaceFirst("%message%", ex.Message()); _NotifyUser("Error", message.String()); return; } BObjectList<BSolverPackage> packages; result = manager.Solver()->FindPackages("", BSolver::B_FIND_CASE_INSENSITIVE | BSolver::B_FIND_IN_NAME | BSolver::B_FIND_IN_SUMMARY | BSolver::B_FIND_IN_DESCRIPTION | BSolver::B_FIND_IN_PROVIDES, packages); if (result != B_OK) { // TODO: notify user return; } if (packages.IsEmpty()) return; PackageInfoMap foundPackages; // if a given package is installed locally, we will potentially // get back multiple entries, one for each local installation // location, and one for each remote repository the package // is available in. The above map is used to ensure that in such // cases we consolidate the information, rather than displaying // duplicates PackageInfoMap remotePackages; // any package that we find in a remote repository goes in this map. // this is later used to discern which packages came from a local // installation only, as those must be handled a bit differently // upon uninstallation, since we'd no longer be able to pull them // down remotely. BStringList systemFlaggedPackages; // any packages flagged as a system package are added to this list. // such packages cannot be uninstalled, nor can any of their deps. PackageInfoMap systemInstalledPackages; // any packages installed in system are added to this list. // This is later used for dependency resolution of the actual // system packages in order to compute the list of protected // dependencies indicated above. BitmapRef defaultIcon(new(std::nothrow) SharedBitmap( "application/x-vnd.haiku-package"), true); for (int32 i = 0; i < packages.CountItems(); i++) { BSolverPackage* package = packages.ItemAt(i); const BPackageInfo& repoPackageInfo = package->Info(); PackageInfoRef modelInfo; PackageInfoMap::iterator it = foundPackages.find( repoPackageInfo.Name()); if (it != foundPackages.end()) modelInfo.SetTo(it->second); else { // Add new package info BString publisherURL; if (repoPackageInfo.URLList().CountStrings() > 0) publisherURL = repoPackageInfo.URLList().StringAt(0); BString publisherName = repoPackageInfo.Vendor(); const BStringList& rightsList = repoPackageInfo.CopyrightList(); if (rightsList.CountStrings() > 0) publisherName = rightsList.StringAt(0); modelInfo.SetTo(new(std::nothrow) PackageInfo( repoPackageInfo.Name(), repoPackageInfo.Version().ToString(), PublisherInfo(BitmapRef(), publisherName, "", publisherURL), repoPackageInfo.Summary(), repoPackageInfo.Description(), repoPackageInfo.Flags()), true); if (modelInfo.Get() == NULL) return; foundPackages[repoPackageInfo.Name()] = modelInfo; } modelInfo->SetIcon(defaultIcon); modelInfo->AddListener(this); BSolverRepository* repository = package->Repository(); if (dynamic_cast<BPackageManager::RemoteRepository*>(repository) != NULL) { depots[repository->Name()].AddPackage(modelInfo); remotePackages[modelInfo->Title()] = modelInfo; } else { if (repository == static_cast<const BSolverRepository*>( manager.SystemRepository())) { modelInfo->AddInstallationLocation( B_PACKAGE_INSTALLATION_LOCATION_SYSTEM); if (!modelInfo->IsSystemPackage()) { systemInstalledPackages[repoPackageInfo.FileName()] = modelInfo; } } else if (repository == static_cast<const BSolverRepository*>( manager.HomeRepository())) { modelInfo->AddInstallationLocation( B_PACKAGE_INSTALLATION_LOCATION_HOME); } } if (modelInfo->IsSystemPackage()) systemFlaggedPackages.Add(repoPackageInfo.FileName()); } BAutolock lock(fModel.Lock()); fModel.Clear(); // filter remote packages from the found list // any packages remaining will be locally installed packages // that weren't acquired from a repository for (PackageInfoMap::iterator it = remotePackages.begin(); it != remotePackages.end(); it++) { foundPackages.erase(it->first); } if (!foundPackages.empty()) { BString repoName = B_TRANSLATE("Local"); depots[repoName] = DepotInfo(repoName); DepotInfoMap::iterator depot = depots.find(repoName); for (PackageInfoMap::iterator it = foundPackages.begin(); it != foundPackages.end(); ++it) { depot->second.AddPackage(it->second); } } for (DepotInfoMap::iterator it = depots.begin(); it != depots.end(); it++) { fModel.AddDepot(it->second); } // start retrieving package icons and average ratings fModel.PopulateAllPackages(); // compute the OS package dependencies try { // create the solver BSolver* solver; status_t error = BSolver::Create(solver); if (error != B_OK) throw BFatalErrorException(error, "Failed to create solver."); ObjectDeleter<BSolver> solverDeleter(solver); BPath systemPath; error = find_directory(B_SYSTEM_PACKAGES_DIRECTORY, &systemPath); if (error != B_OK) { throw BFatalErrorException(error, "Unable to retrieve system packages directory."); } // add the "installed" repository with the given packages BSolverRepository installedRepository; { BRepositoryBuilder installedRepositoryBuilder(installedRepository, "installed"); for (int32 i = 0; i < systemFlaggedPackages.CountStrings(); i++) { BPath packagePath(systemPath); packagePath.Append(systemFlaggedPackages.StringAt(i)); installedRepositoryBuilder.AddPackage(packagePath.Path()); } installedRepositoryBuilder.AddToSolver(solver, true); } // add system repository BSolverRepository systemRepository; { BRepositoryBuilder systemRepositoryBuilder(systemRepository, "system"); for (PackageInfoMap::iterator it = systemInstalledPackages.begin(); it != systemInstalledPackages.end(); it++) { BPath packagePath(systemPath); packagePath.Append(it->first); systemRepositoryBuilder.AddPackage(packagePath.Path()); } systemRepositoryBuilder.AddToSolver(solver, false); } // solve error = solver->VerifyInstallation(); if (error != B_OK) { throw BFatalErrorException(error, "Failed to compute packages to " "install."); } BSolverResult solverResult; error = solver->GetResult(solverResult); if (error != B_OK) { throw BFatalErrorException(error, "Failed to retrieve system " "package dependency list."); } for (int32 i = 0; const BSolverResultElement* element = solverResult.ElementAt(i); i++) { BSolverPackage* package = element->Package(); if (element->Type() == BSolverResultElement::B_TYPE_INSTALL) { PackageInfoMap::iterator it = systemInstalledPackages.find( package->Info().FileName()); if (it != systemInstalledPackages.end()) it->second->SetSystemDependency(true); } } } catch (BFatalErrorException ex) { printf("Fatal exception occurred while resolving system dependencies: " "%s, details: %s\n", strerror(ex.Error()), ex.Details().String()); } catch (BNothingToDoException) { // do nothing } catch (BException ex) { printf("Exception occurred while resolving system dependencies: %s\n", ex.Message().String()); } catch (...) { printf("Unknown exception occurred while resolving system " "dependencies.\n"); } }
thread_id TeamDebugHandler::_EnterDebugger(bool saveReport) { TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): team %" B_PRId32 "\n", fTeam)); // prepare a debugger handover TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): preparing " "debugger handover for team %" B_PRId32 "...\n", fTeam)); status_t error = send_debug_message(&fDebugContext, B_DEBUG_MESSAGE_PREPARE_HANDOVER, NULL, 0, NULL, 0); if (error != B_OK) { debug_printf("debug_server: Failed to prepare debugger handover: %s\n", strerror(error)); return error; } BStringList arguments; const char *argv[16]; int argc = 0; bool debugInConsoled = _IsGUIServer() || !_AreGUIServersAlive(); #ifdef HANDOVER_USE_GDB error = _SetupGDBArguments(arguments, debugInConsoled); if (error != B_OK) { debug_printf("debug_server: Failed to set up gdb arguments: %s\n", strerror(error)); return error; } // start the terminal TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): starting " "terminal (debugger) for team %" B_PRId32 "...\n", fTeam)); #elif defined(HANDOVER_USE_DEBUGGER) if (debugInConsoled) { error = _SetupGDBArguments(arguments, debugInConsoled); if (error != B_OK) { debug_printf("debug_server: Failed to set up gdb arguments: %s\n", strerror(error)); return error; } } else { // prepare the argument vector BPath debuggerPath; error = find_directory(B_SYSTEM_APPS_DIRECTORY, &debuggerPath); if (error != B_OK) { debug_printf("debug_server: can't find system-apps directory: %s\n", strerror(error)); return error; } error = debuggerPath.Append("Debugger"); if (error != B_OK) { debug_printf("debug_server: can't append to system-apps path: %s\n", strerror(error)); return error; } if (!arguments.Add(debuggerPath.Path())) return B_NO_MEMORY; BString debuggerParam; debuggerParam.SetToFormat("%" B_PRId32, fTeam); if (saveReport) { if (!arguments.Add("--save-report")) return B_NO_MEMORY; } if (!arguments.Add("--team") || !arguments.Add(debuggerParam)) return B_NO_MEMORY; // start the debugger TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): starting " "graphical debugger for team %" B_PRId32 "...\n", fTeam)); } #endif for (int32 i = 0; i < arguments.CountStrings(); i++) argv[argc++] = arguments.StringAt(i).String(); argv[argc] = NULL; thread_id thread = load_image(argc, argv, (const char**)environ); if (thread < 0) { debug_printf("debug_server: Failed to start debugger: %s\n", strerror(thread)); return thread; } resume_thread(thread); TRACE(("debug_server: TeamDebugHandler::_EnterDebugger(): debugger started " "for team %" B_PRId32 ": thread: %" B_PRId32 "\n", fTeam, thread)); return thread; }