right fix for tmpdir initialized in static constructor
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 19 Jun 2006 11:50:34 +0000 (11:50 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 19 Jun 2006 11:50:34 +0000 (11:50 +0000)
zypp/ZYppCallbacks.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/susetags/SuseTagsImpl.cc
zypp/source/yum/YUMSourceImpl.cc

index 72ec52a..14f1e1e 100644 (file)
@@ -29,7 +29,8 @@ namespace zypp
     {
       enum Action { 
         ABORT,  // abort and return error
-        RETRY  // retry
+        RETRY, // retry
+        IGNORE, // ignore this resolvable but continue
       }; 
       
       enum Error {
index b02de0a..1a8000c 100644 (file)
@@ -99,7 +99,6 @@ namespace zypp
      */
     SourceImpl::SourceImpl( const null & )
        : base::ProvideNumericId<SourceImpl,Source_Ref::NumericId>( NULL )
-        , _tmp_metadata_dir("/var/tmp/zypp.0") 
         , _res_store_initialized(true)
     {}
     
@@ -115,7 +114,6 @@ namespace zypp
     , _priority_unsubscribed (0)
     , _subscribed(false)
     , _base_source(false)
-    , _tmp_metadata_dir(getZYpp()->tmpPath())
     , _res_store_initialized(false)
     {
     }
@@ -195,6 +193,13 @@ namespace zypp
       return const_cast<SourceImpl*>(this)->provideResolvables(self, kind);
     }
 
+    Pathname SourceImpl::tmpMetadataDir() const
+    {
+      if ( !_tmp_metadata_dir_ptr )
+        _tmp_metadata_dir_ptr.reset(new filesystem::TmpDir(getZYpp()->tmpPath()));
+      return _tmp_metadata_dir_ptr->path();
+    }     
+    
     Date SourceImpl::timestamp() const
     {
       return Date::now();
@@ -224,8 +229,16 @@ namespace zypp
 
        callback::TempConnect<media::DownloadProgressReport> tmp_download( download_report );
 
-        file = provideJustFile( package->location(), package->sourceMediaNr());
-
+        try
+        {
+          file = provideJustFile( package->location(), package->sourceMediaNr());
+        }
+        catch (const Exception &e)
+        {
+          ERR << "Failed to provide " << package << " from " << url() << " in source " << alias() << std::endl;
+          ZYPP_RETHROW (e);
+        }
+        
         report->finish( package, source::DownloadResolvableReport::NO_ERROR, "" );
 
         CheckSum checksum = package->checksum();
index 1b4b503..c553424 100644 (file)
@@ -267,6 +267,12 @@ namespace zypp
          * reset the media verifier to no verifier
          */
         void resetMediaVerifier();
+        
+      /**
+         * function that creates the tmp metadata dir if it was not created.
+         * this directory is used when cache_dir is not set (design flaw FIXME)
+       */
+      Pathname tmpMetadataDir() const;
 
     protected:
       /** All resolvables provided by this source. */
@@ -295,7 +301,8 @@ namespace zypp
       /** source contains base product? */
       bool _base_source;
 
-      filesystem::TmpDir _tmp_metadata_dir;
+    private:
+      mutable shared_ptr<filesystem::TmpDir> _tmp_metadata_dir_ptr;
       ///////////////////////////////////////////////////////////////////
       // no playground below this line ;)
       ///////////////////////////////////////////////////////////////////
index 5aaa230..d8f3b25 100644 (file)
@@ -52,7 +52,7 @@ namespace zypp
 
       const Pathname SuseTagsImpl::metadataRoot() const
       {
-        return _cache_dir.empty() ? _tmp_metadata_dir : _cache_dir;
+        return _cache_dir.empty() ? tmpMetadataDir() : _cache_dir;
       }
       
       const Pathname SuseTagsImpl::contentFile() const
@@ -303,7 +303,7 @@ namespace zypp
         else
         {
           // no previous cache, use the data read temporarely
-          copyLocalMetadata(_tmp_metadata_dir.path(), cache_dir_r);
+          copyLocalMetadata(tmpMetadataDir(), cache_dir_r);
         }
         
         MIL << "Metadata saved in " << cache_dir_r << ". Setting as cache." << std::endl;
@@ -385,10 +385,10 @@ namespace zypp
         {
           if ( _cache_dir.empty() || !PathInfo(_cache_dir).isExist() )
           {
-            MIL << "Cache dir not set. Downloading to temp dir: " << _tmp_metadata_dir << std::endl;
+            MIL << "Cache dir not set. Downloading to temp dir: " << tmpMetadataDir() << std::endl;
             // as we have no local dir set we use a tmp one, but we use a member variable because
             // it cant go out of scope while the source exists.
-            saveMetadataTo(_tmp_metadata_dir);
+            saveMetadataTo(tmpMetadataDir());
           }
           else
           {
index 5c35c8f..c8ef105 100644 (file)
@@ -81,7 +81,7 @@ namespace zypp
 
       const Pathname YUMSourceImpl::metadataRoot() const
       {
-        return _cache_dir.empty() ? _tmp_metadata_dir : _cache_dir;
+        return _cache_dir.empty() ? tmpMetadataDir() : _cache_dir;
       }
 
       const Pathname YUMSourceImpl::repomdFile() const
@@ -246,10 +246,10 @@ namespace zypp
         {
           if ( _cache_dir.empty() || !PathInfo(_cache_dir).isExist() )
           {
-            DBG << "Cache dir not set. Downloading to temp dir: " << _tmp_metadata_dir << std::endl;
+            DBG << "Cache dir not set. Downloading to temp dir: " << tmpMetadataDir() << std::endl;
             // as we have no local dir set we use a tmp one, but we use a member variable because
             // it cant go out of scope while the source exists.
-            saveMetadataTo(_tmp_metadata_dir);
+            saveMetadataTo(tmpMetadataDir());
           }
           else
           {
@@ -339,7 +339,7 @@ namespace zypp
         else
         {
           // no previous cache, use the data read temporarely
-          copyLocalMetadata(_tmp_metadata_dir.path(), cache_dir_r);
+          copyLocalMetadata(tmpMetadataDir(), cache_dir_r);
         }
 
         MIL << "Metadata saved in " << cache_dir_r << ". Setting as cache." << std::endl;