Mailinglist Archive: zypp-devel (39 mails)

< Previous Next >
[zypp-devel] [PATCH] Properly determine $releasever on Fedora and RH systems
  • From: Lorenzo Villani <lvillani@xxxxxxxxxxxxxxx>
  • Date: Sat, 11 Jul 2009 14:49:34 +0200
  • Message-id: <200907111449.38489.lvillani@xxxxxxxxxxxxxxx>
This patch also add an example under examples/ and a cmake conditional to build
it.

Cheers,
L.V.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8563bf4..c525674 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -173,7 +173,9 @@ ADD_SUBDIRECTORY( zypp )
# do not build devel by default
ADD_SUBDIRECTORY( devel EXCLUDE_FROM_ALL )
ADD_SUBDIRECTORY( tools )
-#ADD_SUBDIRECTORY( examples )
+IF (DEFINED WITH_EXAMPLES)
+ ADD_SUBDIRECTORY( examples )
+ENDIF (DEFINED WITH_EXAMPLES)
ADD_SUBDIRECTORY( po EXCLUDE_FROM_ALL )
ADD_SUBDIRECTORY( doc )
ADD_SUBDIRECTORY( vendor )
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 2beb5d3..5450f03 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,10 +1,4 @@
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )

-
-########### next target ###############
-
-SET(read_plaindir_source_SRCS
-read_plaindir_source.cc
-)
-
-ADD_EXECUTABLE(read_plaindir_source ${read_plaindir_source_SRCS})
+ADD_EXECUTABLE(whatprovides whatprovides.cc)
+TARGET_LINK_LIBRARIES(whatprovides zypp)
diff --git a/examples/whatprovides.cc b/examples/whatprovides.cc
new file mode 100644
index 0000000..7513b38
--- /dev/null
+++ b/examples/whatprovides.cc
@@ -0,0 +1,32 @@
+#include <iostream>
+
+#include <zypp/ZYpp.h>
+#include <zypp/ZYppFactory.h>
+#include <zypp/PathInfo.h>
+#include <zypp/Capability.h>
+#include <zypp/sat/Solvable.h>
+#include <zypp/sat/WhatProvides.h>
+
+int main(int argc, char **argv) {
+ zypp::ZYpp::Ptr zyppPtr = zypp::ZYppFactory::instance().getZYpp();
+
+ zypp::Pathname sysRoot( "/" );
+
+ zyppPtr->initializeTarget( sysRoot, false );
+ zyppPtr->target()->load();
+
+ std::cout << "Looking for packages which provide " << argv[1] <<
std::endl;
+ zypp::Capability cap(argv[1]);
+ zypp::sat::WhatProvides wp(cap);
+
+ if (wp.empty()) {
+ std::cout << "No providers of " << argv[1] << " found" <<
std::endl;
+ } else {
+ zypp::sat::Solvable package(*wp.begin());
+ std::cout << "Provided by " << package.name() << " version " <<
package.edition().version()
+ << std::endl;
+ }
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc
index ed1a7ca..da14de3 100644
--- a/zypp/target/TargetImpl.cc
+++ b/zypp/target/TargetImpl.cc
@@ -1101,9 +1101,26 @@ namespace zypp
{
if ( _distributionVersion.empty() )
{
+ // By default ZYpp looks for /etc/product.d/baseproduct..
_distributionVersion = baseproductdata( _root ).edition().version();
- if ( !_distributionVersion.empty() )
- MIL << "Remember distributionVersion = '" << _distributionVersion <<
"'" << endl;
+
+ // ...But the baseproduct method is not expected to work on RedHat
derivatives.
+ // On RHEL, Fedora and others the "product version" is determined by
the first package
+ // providing 'redhat-release'. This value is not hardcoded in YUM and
can be configured
+ // with the $distroverpkg variable.
+ if ( _distributionVersion.empty() )
+ {
+ // We need to initialize a target first to find what provides
$distroverpkg
+ getZYpp()->target()->load();
+
+ zypp::Capability cap("redhat-release"); // Hardcoded, for now
+ zypp::sat::WhatProvides wp(cap);
+ zypp::sat::Solvable package(*wp.begin());
+ _distributionVersion = package.edition().version();
+
+ // Unload target
+ getZYpp()->target()->unload();
+ }
}
return _distributionVersion;
}
< Previous Next >