Author: mlandres
Date: Tue Nov 11 18:49:55 2008
New Revision: 11650
URL: http://svn.opensuse.org/viewcvs/zypp?rev=11650&view=rev
Log:
- Avoid superfluous file copying and gpg invocation in keyring handling.
Modified:
trunk/libzypp/VERSION.cmake
trunk/libzypp/devel/devel.ma/NewPool.cc
trunk/libzypp/package/libzypp.changes
trunk/libzypp/zypp/FileChecker.cc
trunk/libzypp/zypp/FileChecker.h
trunk/libzypp/zypp/KeyRing.cc
trunk/libzypp/zypp/PublicKey.cc
trunk/libzypp/zypp/PublicKey.h
trunk/libzypp/zypp/target/rpm/RpmDb.cc
Modified: trunk/libzypp/VERSION.cmake
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/VERSION.cmake?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/VERSION.cmake (original)
+++ trunk/libzypp/VERSION.cmake Tue Nov 11 18:49:55 2008
@@ -60,7 +60,7 @@
#
SET(LIBZYPP_MAJOR "5")
SET(LIBZYPP_COMPATMINOR "21")
-SET(LIBZYPP_MINOR "22")
+SET(LIBZYPP_MINOR "23")
SET(LIBZYPP_PATCH "0")
#
# LAST RELEASED: 5.22.0 (21)
Modified: trunk/libzypp/devel/devel.ma/NewPool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/NewPool.cc?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/NewPool.cc (original)
+++ trunk/libzypp/devel/devel.ma/NewPool.cc Tue Nov 11 18:49:55 2008
@@ -497,7 +497,7 @@
Measure x( "INIT TARGET" );
{
{
- zypp::base::LogControl::TmpLineWriter shutUp;
+ //zypp::base::LogControl::TmpLineWriter shutUp;
getZYpp()->initializeTarget( sysRoot );
}
getZYpp()->target()->load();
@@ -507,6 +507,10 @@
}
}
+ ///////////////////////////////////////////////////////////////////
+ INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
+ return 0;
if ( 1 )
{
RepoManager repoManager( makeRepoManager( sysRoot ) );
Modified: trunk/libzypp/package/libzypp.changes
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/package/libzypp.changes?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/package/libzypp.changes (original)
+++ trunk/libzypp/package/libzypp.changes Tue Nov 11 18:49:55 2008
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Tue Nov 11 18:36:33 CET 2008 - ma@suse.de
+
+- Avoid superfluous file copying and gpg invocation in keyring handling.
+- revision 11650
+
+-------------------------------------------------------------------
Tue Nov 11 14:48:52 CET 2008 - ma@suse.de
- Prevent fetcher from processing the same index file twice. (bnc #443644)
Modified: trunk/libzypp/zypp/FileChecker.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/FileChecker.cc?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/zypp/FileChecker.cc (original)
+++ trunk/libzypp/zypp/FileChecker.cc Tue Nov 11 18:49:55 2008
@@ -32,7 +32,7 @@
//MIL << "checking " << file << " file against checksum '" << _checksum << "'" << endl;
callback::SendReport<DigestReport> report;
CheckSum real_checksum( _checksum.type(), filesystem::checksum( file, _checksum.type() ));
-
+
if ( _checksum.empty() )
{
MIL << "File " << file << " has no checksum available." << std::endl;
@@ -85,13 +85,13 @@
}
}
}
-
+
void CompositeFileChecker::add( const FileChecker &checker )
{
//MIL << "||# " << _checkers.size() << endl;
_checkers.push_back(checker);
//MIL << "||* " << _checkers.size() << endl;
-
+
}
SignatureFileChecker::SignatureFileChecker( const Pathname &signature )
@@ -105,10 +105,12 @@
{
}
- void SignatureFileChecker::addPublicKey( const Pathname &publickey, const KeyContext & keycontext )
+ void SignatureFileChecker::addPublicKey( const Pathname & publickey, const KeyContext & keycontext )
+ { addPublicKey( PublicKey(publickey), keycontext ); }
+
+ void SignatureFileChecker::addPublicKey( const PublicKey & publickey, const KeyContext & keycontext )
{
- ZYpp::Ptr z = getZYpp();
- z->keyRing()->importKey(publickey, false);
+ getZYpp()->keyRing()->importKey(publickey, false);
_context = keycontext;
}
Modified: trunk/libzypp/zypp/FileChecker.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/FileChecker.h?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/zypp/FileChecker.h (original)
+++ trunk/libzypp/zypp/FileChecker.h Tue Nov 11 18:49:55 2008
@@ -24,6 +24,8 @@
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ class PublicKey;
+
/**
* Functor signature used to check files.
* \param file File to check.
@@ -32,7 +34,7 @@
* validate and the user don't want to continue.
*/
typedef function FileChecker;
-
+
class FileCheckException : public Exception
{
public:
@@ -40,21 +42,21 @@
: Exception(msg)
{}
};
-
+
class CheckSumCheckException : public FileCheckException
{
//TODO
};
-
+
class SignatureCheckException : public FileCheckException
{
//TODO
};
-
+
/**
* Built in file checkers
*/
-
+
/**
* \short Checks for a valid checksum and interacts with the user.
*/
@@ -76,7 +78,7 @@
private:
CheckSum _checksum;
};
-
+
/**
* \short Checks for the validity of a signature
*/
@@ -101,7 +103,10 @@
/**
* add a public key to the list of known keys
*/
- void addPublicKey( const Pathname &publickey, const KeyContext & keycontext = KeyContext());
+ void addPublicKey( const PublicKey & publickey, const KeyContext & keycontext = KeyContext());
+ /** \overload Convenience taking the public keys pathname. */
+ void addPublicKey( const Pathname & publickey, const KeyContext & keycontext = KeyContext());
+
/**
* \short Try to validate the file
* \param file File to validate.
@@ -124,10 +129,10 @@
public:
void operator()( const Pathname &file ) const;
};
-
+
/**
* \short Checker composed of more checkers.
- *
+ *
* Allows to create a checker composed of various
* checkers altothether. It will only
* validate if all the checkers validate.
Modified: trunk/libzypp/zypp/KeyRing.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/KeyRing.cc?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/zypp/KeyRing.cc (original)
+++ trunk/libzypp/zypp/KeyRing.cc Tue Nov 11 18:49:55 2008
@@ -258,15 +258,13 @@
PublicKey KeyRing::Impl::exportKey( string id, const Pathname &keyring)
{
TmpFile tmp_file( _base_dir, "pubkey-"+id+"-" );
- Pathname keyfile = tmp_file.path();
- MIL << "Going to export key " << id << " from " << keyring << " to " << keyfile << endl;
+ MIL << "Going to export key " << id << " from " << keyring << " to " << tmp_file.path() << endl;
try {
- ofstream os(keyfile.asString().c_str());
+ ofstream os(tmp_file.path().c_str());
dumpPublicKey( id, keyring, os );
os.close();
- PublicKey key(keyfile);
- return key;
+ return PublicKey( tmp_file );
}
catch (BadKeyException &e)
{
@@ -279,7 +277,7 @@
}
catch (exception &e)
{
- ERR << "Cannot export key " << id << " from " << keyring << " keyring to file " << keyfile << endl;
+ ERR << "Cannot export key " << id << " from " << keyring << " keyring to file " << tmp_file.path() << endl;
}
return PublicKey();
}
@@ -418,7 +416,7 @@
{
MIL << "User does not want to trust key " << id << " " << key.name() << endl;
return false;
- }
+ }
}
else
{
Modified: trunk/libzypp/zypp/PublicKey.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PublicKey.cc?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/zypp/PublicKey.cc (original)
+++ trunk/libzypp/zypp/PublicKey.cc Tue Nov 11 18:49:55 2008
@@ -32,6 +32,8 @@
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
//
// CLASS NAME : PublicKey::Impl
//
@@ -41,12 +43,24 @@
Impl()
{}
- Impl(const Pathname &file)
+ Impl( const Pathname & keyfile )
{
- readFromFile(file);
- MIL << "Done reading key" << std::endl;
+ PathInfo info( keyfile );
+ MIL << "Takeing pubkey from " << keyfile << " of size " << info.size() << " and sha1 " << filesystem::checksum(keyfile, "sha1") << endl;
+
+ if ( !info.isExist() )
+ ZYPP_THROW(Exception("Can't read public key from " + keyfile.asString() + ", file not found"));
+
+ if ( copy( keyfile, _data_file.path() ) != 0 )
+ ZYPP_THROW(Exception("Can't copy public key data from " + keyfile.asString() + " to " + _data_file.path().asString() ));
+
+ readFromFile();
}
+ Impl( const filesystem::TmpFile & sharedfile )
+ : _data_file( sharedfile )
+ { readFromFile(); }
+
public:
/** Offer default Impl. */
static shared_ptr<Impl> nullimpl()
@@ -55,50 +69,38 @@
return _nullimpl;
}
+ std::string asString() const
+ { return "[" + id() + "-" + str::hexstring(created(),8).substr(2) + "] [" + name() + "] [" + fingerprint() + "]"; }
- std::string asString() const
- {
- return "[" + id() + "-" + str::hexstring(created(),8).substr(2) + "] [" + name() + "] [" + fingerprint() + "]";
- }
-
- std::string armoredData() const
- { return _data; }
+ std::string armoredData() const
+ { return _data; }
- std::string id() const
- { return _id; }
+ std::string id() const
+ { return _id; }
- std::string name() const
- { return _name; }
+ std::string name() const
+ { return _name; }
- std::string fingerprint() const
- { return _fingerprint; }
+ std::string fingerprint() const
+ { return _fingerprint; }
- Date created() const
- { return _created; }
+ Date created() const
+ { return _created; }
- Date expires() const
- { return _expires; }
+ Date expires() const
+ { return _expires; }
- Pathname path() const
- {
- return _data_file.path();
- //return _data_file;
- }
+ Pathname path() const
+ { return _data_file.path(); }
protected:
- void readFromFile( const Pathname &keyfile)
- {
-
- PathInfo info(keyfile);
- MIL << "Reading pubkey from " << keyfile << " of size " << info.size() << " and sha1 " << filesystem::checksum(keyfile, "sha1")<< endl;
- if ( !info.isExist() )
- ZYPP_THROW(Exception("Can't read public key from " + keyfile.asString() + ", file not found"));
-
- if ( copy( keyfile, _data_file.path() ) != 0 )
- ZYPP_THROW(Exception("Can't copy public key data from " + keyfile.asString() + " to " + _data_file.path().asString() ));
+ void readFromFile()
+ {
+ PathInfo info( _data_file.path() );
+ MIL << "Reading pubkey from " << info.path() << " of size " << info.size() << " and sha1 " << filesystem::checksum(info.path(), "sha1") << endl;
- filesystem::TmpDir dir;
+ static filesystem::TmpDir dir;
const char* argv[] =
{
"gpg",
@@ -183,26 +185,29 @@
prog.close();
if ( _id.size() == 0 )
- ZYPP_THROW( BadKeyException( "File " + keyfile.asString() + " doesn't contain public key data" , keyfile ) );
+ ZYPP_THROW( BadKeyException( "File " + _data_file.path().asString() + " doesn't contain public key data" , _data_file.path() ) );
//replace all escaped semicolon with real ':'
str::replaceAll( _name, "\\x3a", ":" );
- }
- private:
- std::string _id;
- std::string _name;
- std::string _fingerprint;
- std::string _data;
- filesystem::TmpFile _data_file;
- Date _created;
- Date _expires;
- //Pathname _data_file;
- private:
- friend Impl * rwcowClone<Impl>( const Impl * rhs );
- /** clone for RWCOW_pointer */
- Impl * clone() const
- { return new Impl( *this ); }
+ MIL << "Read pubkey from " << info.path() << ": " << asString() << endl;
+ }
+
+ private:
+ filesystem::TmpFile _data_file;
+
+ std::string _id;
+ std::string _name;
+ std::string _fingerprint;
+ std::string _data;
+ Date _created;
+ Date _expires;
+
+ private:
+ friend Impl * rwcowClone<Impl>( const Impl * rhs );
+ /** clone for RWCOW_pointer */
+ Impl * clone() const
+ { return new Impl( *this ); }
};
///////////////////////////////////////////////////////////////////
@@ -215,9 +220,14 @@
: _pimpl( Impl::nullimpl() )
{}
- PublicKey::PublicKey( const Pathname &file )
+ PublicKey::PublicKey( const Pathname & file )
: _pimpl( new Impl(file) )
{}
+
+ PublicKey::PublicKey( const filesystem::TmpFile & sharedfile )
+ : _pimpl( new Impl(sharedfile) )
+ {}
+
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PublicKey::~PublicKey
@@ -233,9 +243,7 @@
///////////////////////////////////////////////////////////////////
std::string PublicKey::asString() const
- {
- return _pimpl->asString();
- }
+ { return _pimpl->asString(); }
std::string PublicKey::armoredData() const
{ return _pimpl->armoredData(); }
Modified: trunk/libzypp/zypp/PublicKey.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PublicKey.h?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/zypp/PublicKey.h (original)
+++ trunk/libzypp/zypp/PublicKey.h Tue Nov 11 18:49:55 2008
@@ -26,6 +26,11 @@
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ namespace filesystem
+ {
+ class TmpFile;
+ }
+
/**
* Exception thrown when the supplied key is
* not a valid gpg key
@@ -64,7 +69,9 @@
// CLASS NAME : PublicKey
//
/**
- * Class that represent a GPG Public Key
+ * Class that represent a GPG Public Key.
+ *
+ *
*/
class PublicKey
{
@@ -75,11 +82,28 @@
class Impl;
public:
+ /** Default ctor. */
PublicKey();
- /** Ctor
- * \throws when data does not make a key
- */
- PublicKey(const Pathname &file);
+
+ /** Ctor taking the key from a file.
+ *
+ * This is quite expensive, as a copy of the file is created and
+ * used. If you can construct PublicKey from a \ref filesystem::TmpFile,
+ * this prevents copying.
+ *
+ * \throws when data does not make a key
+ */
+ explicit
+ PublicKey( const Pathname & file );
+
+ /** Ctor reading the key from a \ref TmpFile.
+ *
+ * PublicKey holds a reference on the TmpFile providing the key.
+ *
+ * \throws when data does not make a key
+ */
+ explicit
+ PublicKey( const filesystem::TmpFile & sharedfile );
~PublicKey();
Modified: trunk/libzypp/zypp/target/rpm/RpmDb.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/rpm/RpmDb.cc?rev=11650&r1=11649&r2=11650&view=diff
==============================================================================
--- trunk/libzypp/zypp/target/rpm/RpmDb.cc (original)
+++ trunk/libzypp/zypp/target/rpm/RpmDb.cc Tue Nov 11 18:49:55 2008
@@ -912,8 +912,7 @@
return;
std::list<PublicKey> rpm_keys = pubkeys();
-
- for ( std::list<PublicKey>::const_iterator it = zypp_keys.begin(); it != zypp_keys.end(); ++it)
+ for_( it, zypp_keys.begin(), zypp_keys.end() )
{
// we find only the left part of the long gpg key, as rpm does not support long ids
std::list<PublicKey>::iterator ik = find( rpm_keys.begin(), rpm_keys.end(), (*it));
@@ -926,7 +925,7 @@
// now import the key in rpm
try
{
- importPubkey((*it).path());
+ importPubkey( *it );
MIL << "Trusted key " << (*it).id() << " (" << (*it).name() << ") imported in rpm database." << std::endl;
}
catch (RpmException &e)
@@ -941,17 +940,15 @@
{
MIL << "Exporting rpm keyring into zypp trusted keyring" <keyRing()->trustedPublicKeys();
+ set<Edition> rpm_keys( pubkeyEditions() );
+ list<PublicKey> zypp_keys( getZYpp()->keyRing()->trustedPublicKeys() );
- for ( set<Edition>::const_iterator it = rpm_keys.begin(); it != rpm_keys.end(); ++it)
+ for_( it, rpm_keys.begin(), rpm_keys.end() )
{
// search the zypp key into the rpm keys
// long id is edition version + release
string id = str::toUpper( (*it).version() + (*it).release());
- list<PublicKey>::iterator ik = find( zypp_keys.begin(), zypp_keys.end(), id);
+ list<PublicKey>::iterator ik( find( zypp_keys.begin(), zypp_keys.end(), id) );
if ( ik != zypp_keys.end() )
{
MIL << "Key " << (*it) << " is already in zypp database." << endl;
@@ -959,7 +956,7 @@
else
{
// we export the rpm key into a file
- RpmHeader::constPtr result = new RpmHeader();
+ RpmHeader::constPtr result( new RpmHeader() );
getData( string("gpg-pubkey"), *it, result );
TmpFile file(getZYpp()->tmpPath());
ofstream os;
@@ -982,7 +979,7 @@
// now import the key in zypp
try
{
- getZYpp()->keyRing()->importKey( file.path(), true /*trusted*/);
+ getZYpp()->keyRing()->importKey( PublicKey(file), true /*trusted*/);
MIL << "Trusted key " << (*it) << " imported in zypp keyring." << endl;
}
catch (Exception &e)
@@ -1181,7 +1178,7 @@
//MIL << "-----------------------------------------------" << endl;
os.close();
// read the public key from the dumped file
- PublicKey key(file.path());
+ PublicKey key(file);
ret.push_back(key);
}
catch (exception &e)
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org