From a9bdbf8b075d354b033b9df638f62faecb90e0f1 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 6 Jun 2006 22:57:31 +0000 Subject: [PATCH] =?utf8?q?-=20Merge=20fix=20for=20stalle=20tmpdir=20due=20?= =?utf8?q?to=20cyclic=20references,=20using=20a=20master=20=C2=A0=20TmpDir?= =?utf8?q?=20for=20zypp.=20(#178292)=20.=20There=20is=20still=201=20tmpdir?= =?utf8?q?=20to=20fix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- zypp/KeyRing.cc | 69 ++++++++++++++++++++++--------------- zypp/KeyRing.h | 2 +- zypp/ZYpp.cc | 5 ++- zypp/ZYpp.h | 6 +++- zypp/source/SourceImpl.cc | 5 +-- zypp/source/SourceImpl.h | 2 ++ zypp/source/susetags/SuseTagsImpl.h | 4 --- zypp/source/yum/YUMSourceImpl.h | 3 -- zypp/target/rpm/RpmDb.cc | 6 ++-- zypp/zypp_detail/ZYppImpl.cc | 14 ++++++-- zypp/zypp_detail/ZYppImpl.h | 9 ++++- 11 files changed, 78 insertions(+), 47 deletions(-) diff --git a/zypp/KeyRing.cc b/zypp/KeyRing.cc index c16b5b7..2737835 100644 --- a/zypp/KeyRing.cc +++ b/zypp/KeyRing.cc @@ -82,10 +82,11 @@ namespace zypp /** KeyRing implementation. */ struct KeyRing::Impl { - Impl() + Impl(const Pathname &baseTmpDir) : _general_tmp_dir(baseTmpDir) + , _trusted_tmp_dir(baseTmpDir) + { - _general_kr = _general_tmp_dir.path(); - _trusted_kr = _trusted_tmp_dir.path(); + _base_dir = baseTmpDir; } /* @@ -94,8 +95,8 @@ namespace zypp filesystem::assert_dir(general_kr); filesystem::assert_dir(trusted_kr); - _general_kr = general_kr; - _trusted_kr = trusted_kr; + generalKeyRing() = general_kr; + trustedKeyRing() = trusted_kr; } */ @@ -125,17 +126,18 @@ namespace zypp bool publicKeyExists( std::string id, const Pathname &keyring); - Pathname _general_kr; - Pathname _trusted_kr; - + const Pathname generalKeyRing() const; + const Pathname trustedKeyRing() const; + // Used for trusted and untrusted keyrings TmpDir _trusted_tmp_dir; TmpDir _general_tmp_dir; + Pathname _base_dir; public: /** Offer default Impl. */ static shared_ptr nullimpl() { - static shared_ptr _nullimpl( new Impl ); + static shared_ptr _nullimpl( new Impl( Pathname("/var/tmp") ) ); return _nullimpl; } @@ -146,34 +148,45 @@ namespace zypp { return new Impl( *this ); } }; + + const Pathname KeyRing::Impl::generalKeyRing() const + { + return _general_tmp_dir.path(); + } + + const Pathname KeyRing::Impl::trustedKeyRing() const + { + return _trusted_tmp_dir.path(); + } + void KeyRing::Impl::importKey( const Pathname &keyfile, bool trusted) { - importKey( keyfile, trusted ? _trusted_kr : _general_kr ); + importKey( keyfile, trusted ? trustedKeyRing() : generalKeyRing() ); } void KeyRing::Impl::deleteKey( const std::string &id, bool trusted) { - deleteKey( id, trusted ? _trusted_kr : _general_kr ); + deleteKey( id, trusted ? trustedKeyRing() : generalKeyRing() ); } std::list KeyRing::Impl::publicKeys() { - return publicKeys( _general_kr ); + return publicKeys( generalKeyRing() ); } std::list KeyRing::Impl::trustedPublicKeys() { - return publicKeys( _trusted_kr ); + return publicKeys( trustedKeyRing() ); } bool KeyRing::Impl::verifyFileTrustedSignature( const Pathname &file, const Pathname &signature) { - return verifyFile( file, signature, _trusted_kr ); + return verifyFile( file, signature, trustedKeyRing() ); } bool KeyRing::Impl::verifyFileSignature( const Pathname &file, const Pathname &signature) { - return verifyFile( file, signature, _general_kr ); + return verifyFile( file, signature, generalKeyRing() ); } bool KeyRing::Impl::publicKeyExists( std::string id, const Pathname &keyring) @@ -203,7 +216,7 @@ namespace zypp void KeyRing::Impl::dumpPublicKey( const std::string &id, bool trusted, std::ostream &stream ) { - Pathname keyring = trusted ? _trusted_kr : _general_kr; + Pathname keyring = trusted ? trustedKeyRing() : generalKeyRing(); const char* argv[] = { "gpg", @@ -249,23 +262,23 @@ namespace zypp std::string id = readSignatureKeyId(signature); // doeskey exists in trusted keyring - if ( publicKeyExists( id, _trusted_kr ) ) + if ( publicKeyExists( id, trustedKeyRing() ) ) { - TmpFile trustedKey; + TmpFile trustedKey(_base_dir); exportKey( id, trustedKey.path(), true); PublicKey key = readPublicKey(trustedKey.path()); MIL << "Key " << id << " " << key.name << " is trusted" << std::endl; // it exists, is trusted, does it validates? - if ( verifyFile( file, signature, _trusted_kr ) ) + if ( verifyFile( file, signature, trustedKeyRing() ) ) return true; else return report->askUserToAcceptVerificationFailed( filedesc, key.id, key.name, key.fingerprint ); } else { - if ( publicKeyExists( id, _general_kr ) ) + if ( publicKeyExists( id, generalKeyRing() ) ) { - TmpFile unKey; + TmpFile unKey(_base_dir); exportKey( id, unKey.path(), false); MIL << "Exported key " << id << " to " << unKey << std::endl; @@ -278,11 +291,11 @@ namespace zypp MIL << "User wants to trust key " << id << " " << key.name << std::endl; //dumpFile(unKey.path()); - importKey( unKey.path(), _trusted_kr ); + importKey( unKey.path(), trustedKeyRing() ); emitSignal->trustedKeyAdded( (const KeyRing &)(*this), id, key.name, key.fingerprint ); // emit key added - if ( verifyFile( file, signature, _trusted_kr ) ) + if ( verifyFile( file, signature, trustedKeyRing() ) ) { MIL << "File signature is verified" << std::endl; return true; @@ -330,7 +343,7 @@ namespace zypp PublicKey KeyRing::Impl::readPublicKey( const Pathname &keyfile ) { - TmpDir dir; + TmpDir dir(_base_dir); const char* argv[] = { @@ -506,8 +519,8 @@ namespace zypp { MIL << "Deetermining key id if signature " << signature << std::endl; // HACK create a tmp keyring with no keys - TmpDir dir; - TmpFile fakeData; + TmpDir dir(_base_dir); + TmpFile fakeData(_base_dir); const char* argv[] = { @@ -598,8 +611,8 @@ namespace zypp // METHOD NAME : KeyRing::KeyRing // METHOD TYPE : Ctor // - KeyRing::KeyRing() - : _pimpl( new Impl() ) + KeyRing::KeyRing(const Pathname &baseTmpDir) + : _pimpl( new Impl(baseTmpDir) ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/KeyRing.h b/zypp/KeyRing.h index 03b008a..035684a 100644 --- a/zypp/KeyRing.h +++ b/zypp/KeyRing.h @@ -74,7 +74,7 @@ namespace zypp public: /** Default ctor */ - KeyRing(); + KeyRing(const Pathname &baseTmpDir); //explicit //KeyRing(const Pathname &general_kr, const Pathname &trusted_kr); diff --git a/zypp/ZYpp.cc b/zypp/ZYpp.cc index d14b22b..5d1e51c 100644 --- a/zypp/ZYpp.cc +++ b/zypp/ZYpp.cc @@ -131,9 +131,12 @@ namespace zypp void ZYpp::setArchitecture( const Arch & arch ) { _pimpl->setArchitecture( arch ); } - Pathname ZYpp::homePath() const + const Pathname ZYpp::homePath() const { return _pimpl->homePath(); } + const Pathname ZYpp::tmpPath() const + { return _pimpl->tmpPath(); } + void ZYpp::setHomePath( const Pathname & path ) { _pimpl->setHomePath(path); } diff --git a/zypp/ZYpp.h b/zypp/ZYpp.h index 48991a4..5290455 100644 --- a/zypp/ZYpp.h +++ b/zypp/ZYpp.h @@ -145,7 +145,11 @@ namespace zypp public: /** Get the path where zypp related plugins store persistent data and caches */ - Pathname homePath() const; + const Pathname homePath() const; + + /** Get the path where zypp related plugins store temp data */ + const Pathname tmpPath() const; + /** set the home, if you need to change it */ void setHomePath( const Pathname & path ); diff --git a/zypp/source/SourceImpl.cc b/zypp/source/SourceImpl.cc index fcb1240..16dc46c 100644 --- a/zypp/source/SourceImpl.cc +++ b/zypp/source/SourceImpl.cc @@ -17,7 +17,7 @@ #include "zypp/source/SourceImpl.h" #include "zypp/ZYppCallbacks.h" #include "zypp/SourceManager.h" - +#include "zypp/ZYppFactory.h" #include using std::endl; @@ -107,6 +107,7 @@ namespace zypp , _subscribed(false) , _res_store_initialized(false) , _base_source(false) + , _tmp_metadata_dir(getZYpp()->tmpPath()) { } @@ -129,7 +130,7 @@ namespace zypp _cache_dir = cache_dir_r; _subscribed = true; _base_source = base_source; - + // for sources which are neither CD nor DVD we enable autorefresh by default _autorefresh = media::MediaAccess::canBeVolatile( _url ); diff --git a/zypp/source/SourceImpl.h b/zypp/source/SourceImpl.h index a74f135..759bfcb 100644 --- a/zypp/source/SourceImpl.h +++ b/zypp/source/SourceImpl.h @@ -25,6 +25,7 @@ #include "zypp/Pathname.h" #include "zypp/media/MediaManager.h" #include "zypp/source/MediaSet.h" +#include "zypp/TmpPath.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -289,6 +290,7 @@ namespace zypp /** source contains base product? */ bool _base_source; + filesystem::TmpDir _tmp_metadata_dir; /////////////////////////////////////////////////////////////////// // no playground below this line ;) /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/SuseTagsImpl.h b/zypp/source/susetags/SuseTagsImpl.h index 948eba3..2ed3b66 100644 --- a/zypp/source/susetags/SuseTagsImpl.h +++ b/zypp/source/susetags/SuseTagsImpl.h @@ -22,7 +22,6 @@ #include "zypp/CheckSum.h" #include "zypp/source/susetags/SuseTagsProductImpl.h" #include "zypp/source/susetags/SuseTagsPackageImpl.h" -#include "zypp/TmpPath.h" using namespace zypp::filesystem; @@ -189,9 +188,6 @@ namespace zypp // already running from cache Pathname _media_descr_dir; - // in case we dont have cache - TmpDir _tmp_metadata_dir; - std::string _vendor; std::string _media_id; /** diff --git a/zypp/source/yum/YUMSourceImpl.h b/zypp/source/yum/YUMSourceImpl.h index 2bd26f5..d71715c 100644 --- a/zypp/source/yum/YUMSourceImpl.h +++ b/zypp/source/yum/YUMSourceImpl.h @@ -24,7 +24,6 @@ #include "zypp/Product.h" #include "zypp/Selection.h" #include "zypp/Pattern.h" -#include "zypp/TmpPath.h" using namespace zypp::parser::yum; using namespace zypp::filesystem; @@ -151,8 +150,6 @@ namespace zypp const Pathname repomdFileSignature() const; const Pathname repomdFileKey() const; - TmpDir _tmp_metadata_dir; - typedef struct { zypp::detail::ResImplTraits::Ptr impl; zypp::Package::Ptr package; diff --git a/zypp/target/rpm/RpmDb.cc b/zypp/target/rpm/RpmDb.cc index b2b4894..c489930 100644 --- a/zypp/target/rpm/RpmDb.cc +++ b/zypp/target/rpm/RpmDb.cc @@ -879,7 +879,7 @@ void RpmDb::exportTrustedKeysInZyppKeyRing() // we export the rpm key into a file RpmHeader::constPtr result = new RpmHeader(); getData( std::string("gpg-pubkey"), *it, result ); - TmpFile file; + TmpFile file(getZYpp()->tmpPath()); std::ofstream os; try { @@ -933,7 +933,7 @@ void RpmDb::importZyppKeyRingTrustedKeys() { // key does not exists, we need to import it into rpm // create a temporary file - TmpFile file; + TmpFile file(getZYpp()->tmpPath()); // open the file for writing std::ofstream os; try @@ -1021,7 +1021,7 @@ list RpmDb::pubkeys() const // we export the rpm key into a file RpmHeader::constPtr result = new RpmHeader(); getData( std::string("gpg-pubkey"), edition, result ); - TmpFile file; + TmpFile file(getZYpp()->tmpPath()); std::ofstream os; try { diff --git a/zypp/zypp_detail/ZYppImpl.cc b/zypp/zypp_detail/ZYppImpl.cc index 327cdd1..012b14f 100644 --- a/zypp/zypp_detail/ZYppImpl.cc +++ b/zypp/zypp_detail/ZYppImpl.cc @@ -11,9 +11,11 @@ */ #include +#include #include #include #include "zypp/base/Logger.h" +#include "zypp/base/String.h" #include "zypp/zypp_detail/ZYppImpl.h" #include "zypp/detail/ResImplTraits.h" @@ -72,10 +74,10 @@ namespace zypp , _disk_usage() { MIL << "defaultTextLocale: '" << _textLocale << "'" << endl; - + MIL << "initializing keyring..." << std::endl; //_keyring = new KeyRing(homePath() + Pathname("/keyring/all"), homePath() + Pathname("/keyring/trusted")); - _keyring = new KeyRing(); + _keyring = new KeyRing(tmpPath()); // detect the true architecture struct utsname buf; @@ -357,12 +359,18 @@ namespace zypp //------------------------------------------------------------------------ // target store path - Pathname ZYppImpl::homePath() const + const Pathname ZYppImpl::homePath() const { return _home_path.empty() ? Pathname("/var/lib/zypp") : _home_path; } void ZYppImpl::setHomePath( const Pathname & path ) { _home_path = path; } + const Pathname ZYppImpl::tmpPath() const + { + static TmpDir zypp_tmp_dir("/var/tmp", "zypp."); + return zypp_tmp_dir.path(); + } + /****************************************************************** ** ** FUNCTION NAME : operator<< diff --git a/zypp/zypp_detail/ZYppImpl.h b/zypp/zypp_detail/ZYppImpl.h index e2c2e03..cf327fe 100644 --- a/zypp/zypp_detail/ZYppImpl.h +++ b/zypp/zypp_detail/ZYppImpl.h @@ -14,6 +14,7 @@ #include +#include "zypp/TmpPath.h" #include "zypp/ResPoolManager.h" #include "zypp/SourceFeed.h" #include "zypp/Target.h" @@ -23,6 +24,8 @@ #include "zypp/ZYppCommit.h" #include "zypp/DiskUsageCounter.h" +using namespace zypp::filesystem; + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -125,7 +128,11 @@ namespace zypp void setArchitecture( const Arch & arch ); /** Get the path where zypp related plugins store persistent data and caches */ - Pathname homePath() const; + const Pathname homePath() const; + + /** Get the path where zypp related plugins store tmp data */ + const Pathname tmpPath() const; + /** set the home, if you need to change it */ void setHomePath( const Pathname & path ); -- 2.7.4