*
*/
#include <iostream>
+#include <string>
#include "zypp/base/Logger.h"
#include "zypp/base/Exception.h"
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;
+ }
/** 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. */
//
// 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 "";
}
///////////////////////////////////////////////////////////////////
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.