Advertisement
Guest User

boyd

a guest
Dec 6th, 2007
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.88 KB | None | 0 0
  1. static gboolean
  2. backend_get_depends_thread (PkBackend *backend, gpointer data)
  3. {
  4.     // Note: I talked with duncanmv in #zypp and he suggested the
  5.     // way we could suppor this method would be to mark the desired
  6.     // package to be installed, run the dependency solver, and then
  7.     // check the other packages that got marked to install:
  8. /*
  9. 08:55 < duncanmv> run the solver
  10. 08:56 < duncanmv> and then iterate the poll and look packages which status isBySolver() true
  11. 08:56 < duncanmv> which are the packages marked by the solver
  12. 08:56 < duncanmv> you can say that status toBeInstalled() and bySolver are requires
  13. */
  14.     ThreadData *d = (ThreadData*) data;
  15.  
  16.     pk_backend_change_status (backend, PK_STATUS_ENUM_QUERY);
  17.     pk_backend_change_percentage (backend, 0);
  18.  
  19.     PkPackageId *pi = pk_package_id_new_from_string (d->package_id);
  20.         if (pi == NULL) {
  21.                 pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
  22.         g_free (d->package_id);
  23.         g_free (d);
  24.         pk_backend_finished (backend);
  25.                 return FALSE;
  26.         }
  27.  
  28.     zypp::ZYpp::Ptr zypp;
  29.     zypp = get_zypp ();
  30.  
  31.     // Load resolvables from all the enabled repositories
  32.     zypp::RepoManager manager;
  33.     std::list <zypp::RepoInfo> repos;
  34.     try
  35.     {
  36.         // TODO: Split the code up so it's not all just in one bit try/catch
  37.  
  38.         repos = manager.knownRepositories();
  39.         for (std::list <zypp::RepoInfo>::iterator it = repos.begin(); it != repos.end(); it++) {
  40.             zypp::RepoInfo repo (*it);
  41.  
  42.             // skip disabled repos
  43.             if (repo.enabled () == false)
  44.                 continue;
  45.  
  46.             zypp::Repository repository = manager.createFromCache (*it);
  47.             zypp->addResolvables (repository.resolvables ());
  48.         }
  49.  
  50.         zypp::PoolItem_Ref pool_item = NULL;
  51.         // Iterate over the resolvables and mark the one we want to check its dependencies
  52.         for (zypp::ResPoolProxy::const_iterator it = zypp->poolProxy().byKindBegin <zypp::Package>();
  53.                 it != zypp->poolProxy().byKindEnd <zypp::Package>(); it++) {
  54.             zypp::ui::Selectable::Ptr selectable = *it;
  55.             if (strcmp (selectable->name().c_str(), pi->name) == 0) {
  56.                 // This package matches the name we're looking for and
  57.                 // is available for update/install.
  58.                 zypp::ResObject::constPtr installable = selectable->candidateObj();
  59.                 const char *edition_str = installable->edition().asString().c_str();
  60.  
  61.                 if (strcmp (edition_str, pi->version) == 0) {
  62.                     // this is the one, mark it to be installed
  63.                     selectable->set_status (zypp::ui::S_Install);
  64. fprintf (stderr, "\n\n *** marked a package!!! ***\n\n");
  65.                     pool_item = it;
  66.                     break; // Found it, get out of the for loop
  67.                 }
  68.             }
  69.         }
  70.  
  71.         pk_backend_change_percentage (backend, 40);
  72.  
  73.         if (pool_item == NULL) {
  74.             pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Did not find the specified package.");
  75.             g_free (d->package_id);
  76.             g_free (d);
  77.             pk_backend_finished (backend);
  78.                     return FALSE;
  79.         }
  80.  
  81. //printf ("Resolving dependencies...\n");
  82.         // Gather up any dependencies
  83.         pk_backend_change_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
  84.         if (zypp->resolver ()->resolvePool () == FALSE) {
  85.             // Manual intervention required to resolve dependencies
  86.             // TODO: Figure out what we need to do with PackageKit
  87.             // to pull off interactive problem solving.
  88.             pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Couldn't resolve the package dependencies.");
  89.             g_free (d->package_id);
  90.             g_free (d);
  91.             pk_package_id_free (pi);
  92.             pk_backend_finished (backend);
  93.             return FALSE;
  94.         }
  95.  
  96.         pk_backend_change_percentage (backend, 60);
  97.  
  98.         zypp::solver::detail::ItemCapKindList dep_list = zypp->resolver ().installs (pool_item);
  99.         for (zypp::solver::detail::ItemCapKindList::const_iterator iter = dep_list.begin();
  100.                 iter != dep_list.end(); ++iter) {
  101.            
  102.             gchar *dep_package_id = zypp_build_package_id_from_resolvable (dep_pkg);
  103.             if (dep_package_id != NULL) {
  104.                 pk_backend_package (backend,
  105.                     PK_INFO_ENUM_AVAILABLE,
  106.                     dep_package_id,
  107.                     "TODO: Figure out how to get a package description here.");
  108.                 g_free (dep_package_id);
  109.             }
  110.         }
  111.  
  112.         pk_backend_change_percentage (backend, 100);
  113.     } catch (const zypp::repo::RepoNotFoundException &ex) {
  114.         // TODO: make sure this dumps out the right sring.
  115.         pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, ex.asUserString().c_str() );
  116.         g_free (d->package_id);
  117.         g_free (d);
  118.         pk_package_id_free (pi);
  119.         pk_backend_finished (backend);
  120.         return FALSE;
  121.     } catch (const zypp::Exception &ex) {
  122.         //pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Error enumerating repositories");
  123.         pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
  124.         g_free (d->package_id);
  125.         g_free (d);
  126.         pk_package_id_free (pi);
  127.         pk_backend_finished (backend);
  128.         return FALSE;
  129.     }
  130.  
  131.     g_free (d->package_id);
  132.     g_free (d);
  133.     pk_backend_finished (backend);
  134.     return TRUE;
  135. }
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement