- fix refresh in trunk, aka #186115
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 26 Jun 2006 15:16:33 +0000 (15:16 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 26 Jun 2006 15:16:33 +0000 (15:16 +0000)
zypp/SourceFactory.cc
zypp/SourceFactory.h
zypp/SourceManager.cc
zypp/parser/xmlstore/XMLSourceCacheParser.cc
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/sqlite-source/SqliteSources.cc
zypp/source/susetags/SuseTagsImpl.cc
zypp/source/yum/YUMSourceImpl.cc
zypp/target/store/serialize.cc

index 19f1bff..0900132 100644 (file)
@@ -43,10 +43,11 @@ namespace zypp
       static Source_Ref::Impl_Ptr createSourceImpl( const media::MediaId & media_r,
                                                     const Pathname & path_r,
                                                     const std::string & alias_r,
-                                                    const Pathname & cache_dir_r)
+                                                    const Pathname & cache_dir_r,
+                                                    bool auto_refresh )
       {
         Source_Ref::Impl_Ptr impl( new _SourceImpl );
-        impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, false );
+        impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, false, auto_refresh );
         return impl;
       }
 
@@ -57,10 +58,11 @@ namespace zypp
       static Source_Ref::Impl_Ptr createBaseSourceImpl( const media::MediaId & media_r,
                                                     const Pathname & path_r,
                                                     const std::string & alias_r,
-                                                    const Pathname & cache_dir_r)
+                                                    const Pathname & cache_dir_r,
+                                                    bool auto_refresh )
       {
         Source_Ref::Impl_Ptr impl( new _SourceImpl );
-        impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, true );
+        impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, true, auto_refresh);
         return impl;
       }
 
@@ -128,7 +130,7 @@ namespace zypp
     return Source_Ref::noSource;  
   }
   
-  Source_Ref SourceFactory::createFrom( const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, const bool base_source )
+  Source_Ref SourceFactory::createFrom( const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source )
   {
     if (! url_r.isValid())
       ZYPP_THROW( Exception("Empty URL passed to SourceFactory") );
@@ -153,12 +155,13 @@ namespace zypp
       MIL << "Initializing from cache" << endl;
     }
 
+    bool auto_refresh = media::MediaAccess::canBeVolatile( url_r );
     try
     {
       MIL << "Trying the YUM source" << endl;
       Source_Ref::Impl_Ptr impl( base_source
-       ? Impl::createBaseSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r)
-       : Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r) );
+          ? Impl::createBaseSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
+        : Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
       MIL << "Found the YUM source" << endl;
 
       report->endProbe (url_r);
@@ -174,8 +177,8 @@ namespace zypp
     {
       MIL << "Trying the SUSE tags source" << endl;
       Source_Ref::Impl_Ptr impl( base_source
-       ? Impl::createBaseSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r)
-       : Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r) );
+          ? Impl::createBaseSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
+        : Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
       MIL << "Found the SUSE tags source" << endl;
 
       report->endProbe (url_r);
@@ -216,7 +219,7 @@ namespace zypp
     return Source_Ref(); // not reached!!
   }
 
-  Source_Ref SourceFactory::createFrom( const std::string & type, const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, const bool base_source )
+  Source_Ref SourceFactory::createFrom( const std::string & type, const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source, tribool auto_refresh )
   {
     if (! url_r.isValid())
       ZYPP_THROW( Exception("Empty URL passed to SourceFactory") );
@@ -241,6 +244,10 @@ namespace zypp
       MIL << "Initializing from cache" << endl;
     }
 
+    // Sane default for unknown autorefresh 
+    if ( auto_refresh == indeterminate )
+      auto_refresh = media::MediaAccess::canBeVolatile( url_r );
+    
     try
     {
 
@@ -249,20 +256,20 @@ namespace zypp
       if( type == yum::YUMSourceImpl::typeString() ) {
         MIL << "Trying the YUM source" << endl;
         impl = Source_Ref::Impl_Ptr( base_source
-         ? Impl::createBaseSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r)
-         : Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r) );
+         ? Impl::createBaseSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
+          : Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
         MIL << "Found the YUM source" << endl;
       } else if ( type == susetags::SuseTagsImpl::typeString() ) {
         MIL << "Trying the SUSE tags source" << endl;
         impl = Source_Ref::Impl_Ptr( base_source
-         ? Impl::createBaseSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r)
-         : Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r) );
+            ? Impl::createBaseSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
+          : Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
         MIL << "Found the SUSE tags source" << endl;
       } else if ( type == PlaindirImpl::typeString() ) {
         MIL << "Trying the Plaindir source" << endl;
         impl = Source_Ref::Impl_Ptr( base_source
-         ? Impl::createBaseSourceImpl<PlaindirImpl>(id, path_r, alias_r, cache_dir_r)
-         : Impl::createSourceImpl<PlaindirImpl>(id, path_r, alias_r, cache_dir_r) );
+            ? Impl::createBaseSourceImpl<PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
+          : Impl::createSourceImpl<PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
         MIL << "Found the Plaindir source" << endl;
       } else {
        ZYPP_THROW( Exception ("Cannot create source of unknown type '" + type + "'"));
index c09f236..4a57067 100644 (file)
@@ -15,6 +15,7 @@
 #include <iosfwd>
 #include <string>
 #include <set>
+#include <boost/logic/tribool.hpp>
 
 #include "zypp/base/PtrTypes.h"
 
@@ -23,6 +24,8 @@
 #include "zypp/Url.h"
 #include "zypp/Pathname.h"
 
+using namespace boost;
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -59,12 +62,12 @@ namespace zypp
     /** Construct source.
      * \throw EXCEPTION on fail
     */
-    Source_Ref createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", const bool base_source = false );
+    Source_Ref createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", bool base_source = false );
 
     /** Construct source of a given type.
      * \throw EXCEPTION on fail
     */
-    Source_Ref createFrom( const std::string & type,  const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", const bool base_source = false );
+    Source_Ref createFrom( const std::string & type,  const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source, tribool auto_refresh );
 
   private:
     /** Implementation  */
index 511ffa0..668004b 100644 (file)
@@ -392,12 +392,12 @@ namespace zypp
        }
 
        // Note: Url(it->url).asString() to hide password in logs
-        MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "]" << endl;
+        MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
   
          SourceId id = 0;
   
          try {
-            id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir()) );
+            id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir(), false, it->autorefresh()) );
          }
          catch (const Exception &expt )
          {
@@ -419,7 +419,7 @@ namespace zypp
                      DBG << "CD/DVD devices changed - try again without a devices list"
                          << std::endl;
   
-                      id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir()) );
+                      id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir(), false ) );
   
                      // This worked ... update it->url ?
                      //it->url = url2.asCompleteString();
@@ -453,7 +453,6 @@ namespace zypp
              DBG << "disable source" << endl;
              src.disable();
          }
-          src.setAutorefresh ( it->autorefresh() );
     }
 
     if( !report.empty() )
index dd4caed..fb20230 100644 (file)
@@ -62,17 +62,21 @@ namespace xmlstore {
             string name = _helper.name(child);
             if (name == "enabled")
             {
-              if ( _helper.content(child) == "true" )
+              if ( (_helper.content(child) == "true") || (_helper.content(child) == "1") )
                 dataPtr->setEnabled(true);
-              else
+              else if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") )
                 dataPtr->setEnabled(false);
+              else
+                dataPtr->setEnabled(indeterminate);
             }
             else if (name == "auto-refresh")
             {
-              if ( _helper.content(child) == "true" )
+              if ( (_helper.content(child) == "true") || (_helper.content(child) == "1") )
                 dataPtr->setAutorefresh(true);
-              else
+              if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") )
                 dataPtr->setAutorefresh(false);
+              else
+                dataPtr->setAutorefresh(indeterminate);
             }
             else if (name == "type")
             {
index 3998beb..b762d94 100644 (file)
@@ -127,7 +127,8 @@ namespace zypp
                                   const Pathname & path_r,
                                   const std::string & alias_r,
                                   const Pathname cache_dir_r,
-                                 const bool base_source)
+                                 bool base_source,
+                                  bool auto_refresh )
     {
       _media_set = new MediaSet( selfSourceRef() );
       _url = media_mgr.url( media_r );
@@ -137,10 +138,8 @@ 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 );
-
+      _autorefresh = auto_refresh;
+      
       try
         {
           factoryInit();
index 5e8a742..501465e 100644 (file)
@@ -74,10 +74,10 @@ namespace zypp
        * \throw EXCEPTION on fail
       */
       void factoryCtor( const media::MediaId & media_r,
-                        const Pathname & path_r = "/",
-                        const std::string & alias_r = "",
-                        const Pathname cache_dir_r = "",
-                       const bool base_source = false);
+                        const Pathname & path_r,
+                        const std::string & alias_r,
+                        const Pathname cache_dir_r,
+                       bool base_source, bool auto_refresh);
 
       /** SourceImpl MediaVerifier. */
       class Verifier;
index 9f65347..13cbfbc 100644 (file)
@@ -71,7 +71,7 @@ SqliteSources::createDummy( const Url & url, const string & catalog )
     try {
 
        SqliteSourceImpl *impl = new SqliteSourceImpl ();
-       impl->factoryCtor( mediaid, Pathname(), catalog );
+       impl->factoryCtor( mediaid, Pathname(), catalog, "", false, false );
        impl->setId( catalog );
        impl->setZmdName( catalog );
        impl->setZmdDescription ( catalog );
@@ -212,7 +212,7 @@ SqliteSources::sources( bool zypp_restore, bool refresh )
        try {
 
            SqliteSourceImpl *impl = new SqliteSourceImpl ();
-           impl->factoryCtor( mediaid, Pathname(), alias );
+           impl->factoryCtor( mediaid, Pathname(), alias, "", false, false );
            impl->setId( id );
            impl->setZmdName( name );
            impl->setZmdDescription ( desc );
index 033ffd4..b2f10a8 100644 (file)
@@ -405,6 +405,9 @@ namespace zypp
           // in the media.
           readMediaFile(mediaFile());
           readContentFile(contentFile());
+          
+          if ( autorefresh() )
+            storeMetadata(_cache_dir);
         }
         else
         {
index aa0037a..15a7c7e 100644 (file)
@@ -202,6 +202,8 @@ namespace zypp
         if ( cache )
         {
           DBG << "Cached metadata found in [" << _cache_dir << "]." << endl;
+          if ( autorefresh() )
+            storeMetadata(_cache_dir);
         }
         else
         {
index 9be727a..3ebf376 100644 (file)
@@ -35,13 +35,13 @@ namespace zypp
 namespace storage
 { /////////////////////////////////////////////////////////////////
 
-std::string xml_escape( const std::string &text )
+static std::string xml_escape( const std::string &text )
 {
   iobind::parser::xml_escape_parser parser;
   return parser.escape(text);
 }
 
-std::string xml_tag_enclose( const std::string &text, const std::string &tag, bool escape = false )
+static std::string xml_tag_enclose( const std::string &text, const std::string &tag, bool escape = false )
 {
   std::string result;
   result += "<" + tag + ">";
@@ -55,6 +55,16 @@ std::string xml_tag_enclose( const std::string &text, const std::string &tag, bo
   return result;
 }
 
+static std::ostream & operator<<( std::ostream & str, const tribool obj )
+{
+  if (obj)
+    return str << "true";
+  else if (!obj)
+    return str << "false";
+  else
+    return str << "indeterminate";
+}
+
 /**
  * helper function that builds
  * <tagname lang="code">text</tagname>