- don't throw in begin() if the specified repo is not found in pool,
authorJan Kupec <jkupec@suse.cz>
Tue, 29 Apr 2008 21:27:31 +0000 (21:27 +0000)
committerJan Kupec <jkupec@suse.cz>
Tue, 29 Apr 2008 21:27:31 +0000 (21:27 +0000)
  return end() instead (bnc #384337)
- catch exceptions within size() and empty(), act as if the result is
  empty in such case (bnc #384337)

tests/zypp/PoolQuery_test.cc
zypp/PoolQuery.cc
zypp/PoolQuery.h

index 18bdf26..685380d 100644 (file)
@@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE(pool_query_006)
   PoolQuery q2;
   q2.addString("zypp\\");
   q2.setMatchRegex();
-  BOOST_CHECK_THROW(q2.size(), Exception);
+  BOOST_CHECK_THROW(q2.begin(), Exception);
 }
 
 
index ae71dda..1ab431e 100644 (file)
@@ -377,9 +377,8 @@ attremptycheckend:
       repo = pool.reposFind(theone);
       if (repo == Repository::noRepository)
       {
-        RepoInfo info; info.setAlias(theone);
-        ERR << "Repository not found in sat pool." << endl;
-        ZYPP_THROW(repo::RepoNotFoundException(info));
+        DBG << "Repository '" << theone << "' not found in sat pool." << endl;
+        return end();
       }
     }
 
@@ -850,13 +849,22 @@ attremptycheckend:
 
 
   bool PoolQuery::empty() const
-  { return _pimpl->begin() == _pimpl->end(); }
+  {
+    try { return _pimpl->begin() == _pimpl->end(); }
+    catch (const Exception & ex) {}
+    return true;
+  }
+
 
-  //! \todo collect the result, reuse if not dirty
   PoolQuery::size_type PoolQuery::size() const
   {
     size_type count = 0;
-    for(const_iterator it = _pimpl->begin(); it != _pimpl->end(); ++it, ++count);
+    try
+    {
+      for(const_iterator it = _pimpl->begin(); it != _pimpl->end(); ++it, ++count);
+    }
+    catch (const Exception & ex) {}
+
     return count;
   }
 
index ba04430..c6ff75f 100644 (file)
@@ -66,15 +66,28 @@ namespace zypp
 
     /** Query result accessers. */
     //@{
-    class PoolQueryIterator;
 
-    /** */
+    /**
+     * Compile the query and return an iterator to the result.
+     *
+     * \return An iterator (\ref detail::PoolQueryIterator) returning
+     *         sat::Solvable objects pointing at the beginning of the query result.
+     * \throws \ref Exception if the query was about to use a regex which
+     *         failed to compile.
+     * 
+     * \note Note that PoolQuery is derived from \ref sat::SolvIterMixin which
+     *       makes PoolItem and Selectable iterators automatically available.
+     * \see sat::SolvIterMixin
+     */
     const_iterator begin() const;
-    /** */
+
+    /** An iterator pointing to the end of the query result. */
     const_iterator end() const;
-    /** */
+
+    /** Whether the result is empty. */
     bool empty() const;
-    /** */
+
+    /** Number of solvables in the query result. */
     size_type size() const;
     //@}