- Merge fix for stalle tmpdir due to cyclic references, using a master
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 6 Jun 2006 22:57:31 +0000 (22:57 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 6 Jun 2006 22:57:31 +0000 (22:57 +0000)
  TmpDir for zypp. (#178292) . There is still 1 tmpdir to fix.

zypp/KeyRing.cc
zypp/KeyRing.h
zypp/ZYpp.cc
zypp/ZYpp.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/susetags/SuseTagsImpl.h
zypp/source/yum/YUMSourceImpl.h
zypp/target/rpm/RpmDb.cc
zypp/zypp_detail/ZYppImpl.cc
zypp/zypp_detail/ZYppImpl.h

index c16b5b7..2737835 100644 (file)
@@ -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<Impl> nullimpl()
     {
-      static shared_ptr<Impl> _nullimpl( new Impl );
+      static shared_ptr<Impl> _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<PublicKey> KeyRing::Impl::publicKeys()
   {
-    return publicKeys( _general_kr );
+    return publicKeys( generalKeyRing() );
   }
 
   std::list<PublicKey> 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) )
   {}
 
   ///////////////////////////////////////////////////////////////////
index 03b008a..035684a 100644 (file)
@@ -74,7 +74,7 @@ namespace zypp
 
   public:
     /** Default ctor */
-    KeyRing();
+    KeyRing(const Pathname &baseTmpDir);
     //explicit
     //KeyRing(const Pathname &general_kr, const Pathname &trusted_kr);
 
index d14b22b..5d1e51c 100644 (file)
@@ -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); }
 
index 48991a4..5290455 100644 (file)
@@ -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 );
 
index fcb1240..16dc46c 100644 (file)
@@ -17,7 +17,7 @@
 #include "zypp/source/SourceImpl.h"
 #include "zypp/ZYppCallbacks.h"
 #include "zypp/SourceManager.h"
-
+#include "zypp/ZYppFactory.h"
 #include <fstream>
 
 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 );
 
index a74f135..759bfcb 100644 (file)
@@ -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 ;)
       ///////////////////////////////////////////////////////////////////
index 948eba3..2ed3b66 100644 (file)
@@ -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;
         /**
index 2bd26f5..d71715c 100644 (file)
@@ -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<zypp::source::yum::YUMPackageImpl>::Ptr impl;
            zypp::Package::Ptr package;
index b2b4894..c489930 100644 (file)
@@ -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<PublicKey> 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
       {
index 327cdd1..012b14f 100644 (file)
 */
 
 #include <sys/utsname.h>
+#include <unistd.h>
 #include <iostream>
 #include <fstream>
 #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<<
index e2c2e03..cf327fe 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <iosfwd>
 
+#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 );