- Fix reading of Traget::targetDistribution.
authorMichael Andres <ma@suse.de>
Tue, 9 Sep 2008 09:44:45 +0000 (09:44 +0000)
committerMichael Andres <ma@suse.de>
Tue, 9 Sep 2008 09:44:45 +0000 (09:44 +0000)
- Allow to configure default answers in signature verification workflow.

devel/devel.ma/NewPool.cc
package/libzypp.changes
zypp/KeyRing.cc
zypp/KeyRing.h
zypp/target/TargetImpl.cc

index c6ce7e6..eeb2f24 100644 (file)
@@ -445,15 +445,21 @@ try {
   ResPool   pool( ResPool::instance() );
   sat::Pool satpool( sat::Pool::instance() );
 
+  Edition e("1.a");
+  DBG << e.copmpare( Edition("1a") ) << endl;
+  DBG << e.copmpare( Edition("1=a") ) << endl;
+  DBG << e.copmpare( Edition("1#$%^&*()_a") ) << endl;
+return 0;
   if ( 1 )
   {
     Measure x( "INIT TARGET" );
     {
       {
-        //zypp::base::LogControl::TmpLineWriter shutUp;
+        zypp::base::LogControl::TmpLineWriter shutUp;
         getZYpp()->initializeTarget( sysRoot );
       }
       getZYpp()->target()->load();
+      USR << getZYpp()->target()->targetDistribution() << endl;
     }
   }
 
@@ -479,7 +485,7 @@ try {
           repoManager.cleanCache( nrepo );
         }
         SEC << "refreshMetadata" << endl;
-        repoManager.refreshMetadata( nrepo );
+        //repoManager.refreshMetadata( nrepo );
         SEC << "buildCache" << endl;
         repoManager.buildCache( nrepo );
       }
@@ -529,39 +535,6 @@ try {
   ///////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////
 
-  // access to the Pool of Selectables
-  ResPoolProxy selectablePool( ResPool::instance().proxy() );
-
-  // Iterate it's Products...
-  for_( it, selectablePool.byKindBegin<Product>(), selectablePool.byKindEnd<Product>() )
-  {
-    // The current Product Selectable
-    ui::Selectable::Ptr prodSel( *it );
-    MIL << dump( prodSel ) << endl;
-
-    // It's candiate as Product pointer
-    Product::constPtr prod( prodSel->candidateAsKind<Product>() );
-    if ( prod )
-    {
-      // Not NULL, so there is an available Product.
-      // Get the installed Products it would replace.
-      Product::ReplacedProducts prodReplaces( prod->replacedProducts() );
-
-      // Iterate the replaced Products...
-      for_( it, prodReplaces.begin(), prodReplaces.end() )
-      {
-        // The current replaced Product
-        Product::constPtr replacedProduct( *it );
-        DBG << replacedProduct << endl;
-
-        // and this is how you would get the Selectable that contains
-        // this replacedProduct, in case you need it ..
-        ui::Selectable::Ptr replacedProductsSelectable( ui::Selectable::get( replacedProduct ) );
-        DBG << replacedProductsSelectable << endl;
-      }
-    }
-
-  }
 
 
   ///////////////////////////////////////////////////////////////////
index 4f57805..e6bbcd0 100644 (file)
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+Tue Sep  9 11:40:42 CEST 2008 - ma@suse.de
+
+- Fix reading of Traget::targetDistribution.
+- Allow to configure default answers in signature verification workflow.
+- revision 10968
+
+-------------------------------------------------------------------
 Mon Sep  8 17:11:02 CEST 2008 - jkupec@suse.cz
 
 - CredentialManager added to manage stored credentials
index bdc2e23..ec80891 100644 (file)
@@ -51,25 +51,38 @@ namespace zypp
     return true;
   }
 
+  ///////////////////////////////////////////////////////////////////
+
   namespace
   {
-    bool _keyRingDefaultAccept( getenv("ZYPP_KEYRING_DEFAULT_ACCEPT_ALL") );
+    KeyRingReport::DefaultAccept _keyRingDefaultAccept( KeyRingReport::ACCEPT_NOTHING );
   }
 
-  bool KeyRingReport::askUserToAcceptUnsignedFile( const string &file )
+  KeyRingReport::DefaultAccept KeyRingReport::defaultAccept()
   { return _keyRingDefaultAccept; }
 
+  void KeyRingReport::setDefaultAccept( DefaultAccept value_r )
+  {
+    MIL << "Set new default accept: " << value_r << endl;
+    _keyRingDefaultAccept = value_r;
+  }
+
+  ///////////////////////////////////////////////////////////////////
+
+  bool KeyRingReport::askUserToAcceptUnsignedFile( const string &file )
+  { return _keyRingDefaultAccept.testFlag( ACCEPT_UNSIGNED_FILE ); }
+
   bool KeyRingReport::askUserToAcceptUnknownKey( const string &file, const string &id )
-  { return _keyRingDefaultAccept; }
+  { return _keyRingDefaultAccept.testFlag( ACCEPT_UNKNOWNKEY ); }
 
   bool KeyRingReport::askUserToTrustKey( const PublicKey &key )
-  { return _keyRingDefaultAccept; }
+  { return _keyRingDefaultAccept.testFlag( TRUST_KEY ); }
 
   bool KeyRingReport::askUserToImportKey( const PublicKey &key)
-  { return _keyRingDefaultAccept; }
+  { return _keyRingDefaultAccept.testFlag( IMPORT_KEY ); }
 
   bool KeyRingReport::askUserToAcceptVerificationFailed( const string &file, const PublicKey &key )
-  { return _keyRingDefaultAccept; }
+  { return _keyRingDefaultAccept.testFlag( ACCEPT_VERIFICATION_FAILED ); }
 
   ///////////////////////////////////////////////////////////////////
   //
index 0c47558..f44cd55 100644 (file)
@@ -19,6 +19,7 @@
 #include <string>
 
 #include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/Flags.h"
 #include "zypp/Callback.h"
 #include "zypp/base/PtrTypes.h"
 #include "zypp/Locale.h"
@@ -30,6 +31,10 @@ namespace zypp
 
   DEFINE_PTR_TYPE(KeyRing);
 
+  /** Callbacks from signature verification workflow.
+   *
+   * Per default all methods answer \c false.
+  */
   struct KeyRingReport : public callback::ReportBase
   {
 
@@ -59,7 +64,30 @@ namespace zypp
      */
     virtual bool askUserToImportKey( const PublicKey &key);
     virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key );
+
+    public:
+      /** \name Query/change the default values.
+       * Per default all methods answer \c false.
+       */
+      //@{
+      enum DefaultAcceptBits
+      {
+        ACCEPT_NOTHING             = 0x0000,
+        ACCEPT_UNSIGNED_FILE       = 0x0001,
+        ACCEPT_UNKNOWNKEY          = 0x0002,
+        TRUST_KEY                  = 0x0004,
+        IMPORT_KEY                 = 0x0008,
+        ACCEPT_VERIFICATION_FAILED = 0x0010,
+      };
+      ZYPP_DECLARE_FLAGS(DefaultAccept,DefaultAcceptBits);
+
+      /** Get the active accept bits. */
+      static DefaultAccept defaultAccept();
+      /** Set the active accept bits. */
+      static void setDefaultAccept( DefaultAccept value_r );
+     //@}
   };
+  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(KeyRingReport::DefaultAccept);
 
   struct KeyRingSignals : public callback::ReportBase
   {
@@ -167,20 +195,29 @@ namespace zypp
     /**
      * Follows a signature verification interacting with the user.
      * The bool returned depends on user decision to trust or not.
+     *
+     * To propagate user decisions, either connect to the \ref KeyRingReport
+     * or use its static methods to set the desired defaults.
+     *
+     * \code
+     * struct KeyRingReportReceive : public callback::ReceiveReport<KeyRingReport>
+     * {
+     *   KeyRingReportReceive() { connect(); }
+     *
+     *   // Overload the virtual methods to return the appropriate values.
+     *   virtual bool askUserToAcceptUnsignedFile( const std::string &file );
+     *   ...
+     * };
+     * \endcode
+     * \see \ref KeyRingReport
      */
     bool verifyFileSignatureWorkflow( const Pathname &file, const std::string filedesc, const Pathname &signature);
     bool verifyFileSignature( const Pathname &file, const Pathname &signature);
     bool verifyFileTrustedSignature( const Pathname &file, const Pathname &signature);
 
-/** Dtor */
+    /** Dtor */
     ~KeyRing();
 
-  public:
-
-    /** Synonym for \ref text */
-    //std::string asString() const
-    //{}
-
   private:
     /** Pointer to implementation */
     RWCOW_pointer<Impl> _pimpl;
index caab401..3cd76eb 100644 (file)
@@ -879,25 +879,24 @@ namespace zypp
 
     std::string TargetImpl::targetDistribution() const
     {
-      std::ifstream baseProduct( (_root / "/etc/products.d/baseproduct").c_str() );
-      for( iostr::EachLine in( baseProduct ); in; in.next() )
+      std::ostringstream cmd;
+      cmd << "rpmdb2solv";
+      cmd << " -n";
+      if ( ! _root.empty() )
+        cmd << " -r '" << _root << "'";
+      cmd << " -p '" << Pathname::assertprefix( _root, "/etc/products.d" ) << "'";
+      cmd << " -a distribution.target";
+
+      MIL << "Executing: " << cmd << endl;
+      ExternalProgram prog( cmd.str(), ExternalProgram::Discard_Stderr );
+      for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() )
       {
-        std::string line( str::trim( *in ) );
-        if ( str::hasPrefix( line, "distribution" ) )
-        {
-          std::string::size_type pos( line.find( '=', 12 ) );
-          if ( pos == std::string::npos )
-            continue; // no '=' on line
-          pos = line.find_first_not_of( " \t", pos+1 );
-          if ( pos == std::string::npos )
-            continue; // empty value
-          line.erase( 0, pos );
-          line += "-";
-          line += ZConfig::instance().systemArchitecture().asString();
-          return line;
-        }
+        return str::trim(output);
       }
-      WAR << "No distribution in " << PathInfo(_root / "/etc/products.d/baseproduct") << endl;
+
+      int ret = prog.close();
+      WAR << "Got no output from rpmdb2solv (returned " << ret << ")." << endl;
+
       return std::string();
     }