From 2d103a9337e032cbd31a53cc7d73800c14feb5f5 Mon Sep 17 00:00:00 2001 From: Klaus Kaempf Date: Fri, 3 Feb 2006 20:46:35 +0000 Subject: [PATCH] add 'whoOwnsFile' for "rpm -qf" --- zypp/target/TargetImpl.cc | 21 +++++++++++++++++++-- zypp/target/TargetImpl.h | 6 +++++- zypp/target/rpm/RpmDb.cc | 30 ++++++++++++++++++++++++++++-- zypp/target/rpm/RpmDb.h | 11 +++++++++-- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 1653e51d2..9ee96c3b5 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -10,6 +10,7 @@ * */ #include +#include #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; + } diff --git a/zypp/target/TargetImpl.h b/zypp/target/TargetImpl.h index d212e2168..bdd1a23c0 100644 --- a/zypp/target/TargetImpl.h +++ b/zypp/target/TargetImpl.h @@ -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. */ diff --git a/zypp/target/rpm/RpmDb.cc b/zypp/target/rpm/RpmDb.cc index 8f2085eee..6653a9444 100644 --- a/zypp/target/rpm/RpmDb.cc +++ b/zypp/target/rpm/RpmDb.cc @@ -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 ""; } /////////////////////////////////////////////////////////////////// diff --git a/zypp/target/rpm/RpmDb.h b/zypp/target/rpm/RpmDb.h index 5c5ea8ac7..60d2b6932 100644 --- a/zypp/target/rpm/RpmDb.h +++ b/zypp/target/rpm/RpmDb.h @@ -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. -- 2.34.1