- make install by name case-insensitive (bnc #412496)
authorJan Kupec <jkupec@suse.cz>
Mon, 28 Jul 2008 13:22:19 +0000 (13:22 +0000)
committerJan Kupec <jkupec@suse.cz>
Mon, 28 Jul 2008 13:22:19 +0000 (13:22 +0000)
src/install.cc
src/install.h

index 20d7294..38fc163 100755 (executable)
@@ -15,84 +15,25 @@ using namespace boost;
 
 extern ZYpp::Ptr God;
 
-// copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
-bool ProvideProcess::operator()( const PoolItem& provider )
-{
-  DBG << "Considering " << provider << endl;
-  // 1. compatible arch
-  // 2. best arch
-  // 3. best edition
-
-  // check the repository alias if it's specified
-  if (!_repo.empty() && _repo != provider->repository().info().alias())
-  {
-    DBG << format ("Skipping repository %s (requested: %s)")
-      % provider->repository().info().alias() % _repo << endl;
-    return true;
-  }
-
-  bool is_installed;
-  if (provider->isKind(ResKind::package))
-    is_installed = provider.status().isInstalled();
-  else
-    is_installed = provider.isSatisfied();
-
-  if (!is_installed)
-  {
-    // deselect the item if it's already selected,
-    // only one item should be selected
-    if (provider.status().isToBeInstalled()) {
-      DBG << "  Deselecting" << endl;
-      provider.status().resetTransact(whoWantsIt);
-    }
-
-    // regarding items which are installable only
-    if (!provider->arch().compatibleWith( _architecture )) {
-      DBG << format ("provider %s has incompatible arch '%s'")
-        % provider->name() % provider->arch().asString() << endl;
-    }
-    else if (!item) {
-      DBG << "  First match" << endl;
-      item = provider;
-    }
-    else if (item->arch().compare( provider->arch() ) < 0) {
-      DBG << "  Better arch" << endl;
-      item = provider;
-    }
-    else if (item->edition().compare( provider->edition() ) < 0) {
-      DBG << "  Better edition" << endl;
-      item = provider;
-    }
-  }
-  else {
-    // store encountered target item (installed)
-    installed_item = provider;
-    if (!item) item = provider;
-  }
-
-  return true;
-}
-
-// ----------------------------------------------------------------------------
-
-// this does only resolvables with this _name_.
-// we could also act on _provides_
-// TODO edition, arch
+// TODO edition, arch ?
 static void mark_for_install(Zypper & zypper,
                       const ResObject::Kind &kind,
                       const std::string &name,
                       const std::string & repo = "")
 {
   // name and kind match:
-  ProvideProcess installer (ZConfig::instance().systemArchitecture(), repo);
   DBG << "Iterating over [" << kind << "]" << name << endl;
-  invokeOnEach(
-      God->pool().byIdentBegin(kind, name),
-      God->pool().byIdentEnd(kind, name),
-      zypp::functor::functorRef<bool,const zypp::PoolItem&> (installer));
+
+  PoolQuery q;
+  q.addAttribute(sat::SolvAttr::name, name);
+  if (!repo.empty())
+    q.addRepo(repo);
+  q.setCaseSensitive(false);
+  q.setMatchExact();
 
   DBG << "... done" << endl;
-  if (!installer.item)
+
+  if (q.empty())
   {
     zypper.out().error(
       // translators: meaning a package %s or provider of capability %s
@@ -102,30 +43,34 @@ static void mark_for_install(Zypper & zypper,
     return;
   }
 
-  if (installer.installed_item &&
-      installer.installed_item.resolvable()->edition() == installer.item.resolvable()->edition() &&
-      installer.installed_item.resolvable()->arch() == installer.item.resolvable()->arch() &&
+  ui::Selectable::Ptr s = *q.selectableBegin();
+
+  if (s->installedObj() &&
+      s->installedObj().resolvable()->edition() == s->candidateObj().resolvable()->edition() &&
+      s->installedObj().resolvable()->arch() == s->candidateObj().resolvable()->arch() &&
       ( ! copts.count("force") ) )
   {
     // if it is broken install anyway, even if it is installed
-    if ( installer.item.isBroken() )
+    if ( s->candidateObj().isBroken() )
     {
-      installer.item.status().setTransact( true, zypp::ResStatus::USER );
+      s->candidateObj().status().setTransact( true, zypp::ResStatus::USER );
+    }
+    else
+    {
+      zypper.out().info(boost::str(format(
+        // translators: e.g. skipping package 'zypper' (the newest version already installed)  
+        _("skipping %s '%s' (the newest version already installed)"))
+        % kind_to_string_localized(kind,1) % name));
     }
-
-    zypper.out().info(boost::str(format(
-      // translators: e.g. skipping package 'zypper' (the newest version already installed)  
-      _("skipping %s '%s' (the newest version already installed)"))
-      % kind_to_string_localized(kind,1) % name));
   }
   else {
 
     //! \todo don't use setToBeInstalled for this purpose but higher level solver API
-    bool result = installer.item.status().setToBeInstalled( zypp::ResStatus::USER );
+    bool result = s->candidateObj().status().setToBeInstalled( zypp::ResStatus::USER );
     if (!result)
     {
       // this is because the resolvable is installed and we are forcing.
-      installer.item.status().setTransact( true, zypp::ResStatus::USER );
+      s->candidateObj().status().setTransact( true, zypp::ResStatus::USER );
       if (!copts.count("force"))
       {
         zypper.out().error(boost::str(
@@ -623,3 +568,4 @@ void install_remove(Zypper & zypper,
     mark_by_capability (zypper, install_not_remove, kind, cap);
   }
 }
+
index f357639..e964bca 100755 (executable)
@@ -11,22 +11,4 @@ void install_remove(Zypper & zypper,
                     bool install_not_remove,
                     const zypp::ResKind & kind);
 
-// copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
-struct ProvideProcess
-{
-  zypp::PoolItem item;
-  zypp::PoolItem installed_item;
-  zypp::ResStatus::TransactByValue whoWantsIt;
-  std::string _repo;
-  zypp::Arch _architecture;
-
-  ProvideProcess(zypp::Arch arch, const std::string & repo)
-    : whoWantsIt(zypp::ResStatus::USER)
-    , _repo(repo)
-    , _architecture( arch )
-    { }
-
-  bool operator()( const zypp::PoolItem& provider );
-};
-
 #endif /*INSTALL_H_*/