#
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)
Measure x( "INIT TARGET" );
{
{
- zypp::base::LogControl::TmpLineWriter shutUp;
+ //zypp::base::LogControl::TmpLineWriter shutUp;
getZYpp()->initializeTarget( sysRoot );
}
getZYpp()->target()->load();
}
}
+ ///////////////////////////////////////////////////////////////////
+ INT << "===[END]============================================" << endl << endl;
+ zypp::base::LogControl::instance().logNothing();
+ return 0;
if ( 1 )
{
RepoManager repoManager( makeRepoManager( sysRoot ) );
-------------------------------------------------------------------
+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)
//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;
}
}
}
-
+
void CompositeFileChecker::add( const FileChecker &checker )
{
//MIL << "||# " << _checkers.size() << endl;
_checkers.push_back(checker);
//MIL << "||* " << _checkers.size() << endl;
-
+
}
SignatureFileChecker::SignatureFileChecker( const Pathname &signature )
{
}
- 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;
}
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ class PublicKey;
+
/**
* Functor signature used to check files.
* \param file File to check.
* validate and the user don't want to continue.
*/
typedef function<void ( const Pathname &file )> FileChecker;
-
+
class FileCheckException : public Exception
{
public:
: 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.
*/
private:
CheckSum _checksum;
};
-
+
/**
* \short Checks for the validity of a signature
*/
/**
* 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.
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.
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)
{
}
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();
}
{
MIL << "User does not want to trust key " << id << " " << key.name() << endl;
return false;
- }
+ }
}
else
{
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
//
// CLASS NAME : PublicKey::Impl
//
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()
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",
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 ); }
};
///////////////////////////////////////////////////////////////////
: _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
///////////////////////////////////////////////////////////////////
std::string PublicKey::asString() const
- {
- return _pimpl->asString();
- }
+ { return _pimpl->asString(); }
std::string PublicKey::armoredData() const
{ return _pimpl->armoredData(); }
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ namespace filesystem
+ {
+ class TmpFile;
+ }
+
/**
* Exception thrown when the supplied key is
* not a valid gpg key
// CLASS NAME : PublicKey
//
/**
- * Class that represent a GPG Public Key
+ * Class that represent a GPG Public Key.
+ *
+ *
*/
class PublicKey
{
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();
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));
// 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)
{
MIL << "Exporting rpm keyring into zypp trusted keyring" <<endl;
- set<Edition> rpm_keys = pubkeyEditions();
-
- list<PublicKey> zypp_keys;
- zypp_keys = getZYpp()->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;
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;
// 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)
//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)