add 'whoOwnsFile' for "rpm -qf"
authorKlaus Kaempf <kkaempf@suse.de>
Fri, 3 Feb 2006 20:46:35 +0000 (20:46 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Fri, 3 Feb 2006 20:46:35 +0000 (20:46 +0000)
zypp/target/TargetImpl.cc
zypp/target/TargetImpl.h
zypp/target/rpm/RpmDb.cc
zypp/target/rpm/RpmDb.h

index 1653e51..9ee96c3 100644 (file)
@@ -10,6 +10,7 @@
  *
 */
 #include <iostream>
+#include <string>
 #include "zypp/base/Logger.h"
 #include "zypp/base/Exception.h"
 
@@ -195,8 +196,24 @@ namespace zypp
     rpm::RpmDb & TargetImpl::rpm()
     { return _rpm; }
 
-    bool TargetImpl::providesFile (const std::string & name_str, const std::string & path_str) const
-    { return _rpm.hasFile(path_str); }
+    bool TargetImpl::providesFile (const std::string & path_str, const std::string & name_str) const
+    { return _rpm.hasFile(path_str, name_str); }
+
+      /** Return the resolvable which provides path_str (rpm -qf)
+         return NULL if no resolvable provides this file  */
+    ResObject::constPtr TargetImpl::whoOwnsFile (const std::string & path_str) const
+    {
+       string name = _rpm.whoOwnsFile (path_str);
+       if (name.empty())
+           return NULL;
+
+       for (ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it) {
+           if ((*it)->name() == name) {
+               return *it;
+           }
+       }
+       return NULL;
+    }
 
 
 
index d212e21..bdd1a23 100644 (file)
@@ -83,7 +83,11 @@ namespace zypp
 
       /** If the package is installed and provides the file
          Needed to evaluate split provides during Resolver::Upgrade() */
-      bool providesFile (const std::string & name_str, const std::string & path_str) const;
+      bool providesFile (const std::string & path_str, const std::string & name_str) const;
+
+      /** Return the resolvable which provides path_str (rpm -qf)
+         return NULL if no resolvable provides this file  */
+      ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
 
     protected:
       /** All resolvables provided by the target. */
index 8f2085e..6653a94 100644 (file)
@@ -1186,10 +1186,36 @@ void RpmDb::traceFileRel( const PkgRelation & rel_r )
 //
 //     DESCRIPTION :
 //
-bool RpmDb::hasFile( const std::string & file_r ) const
+bool RpmDb::hasFile( const std::string & file_r, const std::string & name_r ) const
 {
   librpmDb::db_const_iterator it;
-  return it.findByFile( file_r );
+  bool res;
+  do {
+    res = it.findByFile( file_r );
+    if (!res) break;
+    if (!name_r.empty()) {
+      res = (it->tag_name() == name_r);
+    }
+    ++it;
+  } while (res && *it);
+  return res;
+}
+
+///////////////////////////////////////////////////////////////////
+//
+//
+//     METHOD NAME : RpmDb::whoOwnsFile
+//     METHOD TYPE : string
+//
+//     DESCRIPTION :
+//
+std::string RpmDb::whoOwnsFile( const std::string & file_r) const
+{
+  librpmDb::db_const_iterator it;
+  if (it.findByFile( file_r )) {
+    return it->tag_name();
+  }
+  return "";
 }
 
 ///////////////////////////////////////////////////////////////////
index 5c5ea8a..60d2b69 100644 (file)
@@ -254,9 +254,16 @@ namespace zypp {
         public:
       
           /**
-           * Return true if at least one package owns a certain file.
+           * Return true if at least one package owns a certain file (name_r empty)
+           * Return true if package name_r owns file file_r (name_r nonempty).
            **/
-          bool hasFile( const std::string & file_r ) const;
+          bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
+      
+          /**
+           * Return name of package owning file
+           * or empty string if no installed package owns file
+           **/
+          std::string whoOwnsFile( const std::string & file_r ) const;
       
           /**
            * Return true if at least one package provides a certain tag.