- YaST sources:
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 9 Oct 2006 16:14:41 +0000 (16:14 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 9 Oct 2006 16:14:41 +0000 (16:14 +0000)
  Factory cannot be set with 'refresh' enabled
  (#204957)

zypp/Source.cc
zypp/Source.h
zypp/SourceFactory.cc
zypp/SourceManager.cc
zypp/parser/xmlstore/XMLSourceCacheParser.cc
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/SourceInfo.cc
zypp/source/susetags/SuseTagsImpl.cc

index dd43685..08539bc 100644 (file)
@@ -80,10 +80,10 @@ namespace zypp
 
   const void Source_Ref::releaseDir(const Pathname & dir_r,
                                     const unsigned media_nr,
-                                    const bool recursive)
+                                    bool recursive)
   { _pimpl->releaseDir(dir_r, media_nr, recursive); }
 
-  const bool Source_Ref::enabled() const
+  bool Source_Ref::enabled() const
   { return _pimpl->enabled(); }
 
   void Source_Ref::enable()
@@ -98,10 +98,10 @@ namespace zypp
   std::string Source_Ref::checksum() const
   { return _pimpl->checksum(); }
   
-  const bool Source_Ref::autorefresh() const
+  bool Source_Ref::autorefresh() const
   { return _pimpl->autorefresh(); }
 
-  void Source_Ref::setAutorefresh( const bool enable_r )
+  void Source_Ref::setAutorefresh( bool enable_r )
   { _pimpl->setAutorefresh( enable_r ); }
 
   void Source_Ref::refresh()
@@ -167,7 +167,7 @@ namespace zypp
   const Pathname & Source_Ref::path (void) const
   { return _pimpl->path (); }
 
-  const bool Source_Ref::baseSource() const
+  bool Source_Ref::baseSource() const
   { return _pimpl->baseSource(); }
 
   const Pathname & Source_Ref::cacheDir (void) const
index f55158c..aea5306 100644 (file)
@@ -183,25 +183,20 @@ namespace zypp
     const Pathname providePackage( Package::constPtr package );
     
     /** Provide a file to local filesystem */
-    const Pathname provideFile(const Pathname & file_r,
-                              const unsigned media_nr = 1);
-    const Pathname provideDirTree(const Pathname & dir_r,
-                                  const unsigned media_nr = 1);
+    const Pathname provideFile(const Pathname & file_r, const unsigned media_nr = 1);
+    const Pathname provideDirTree(const Pathname & dir_r, const unsigned media_nr = 1);
                              
-    const void releaseFile(const Pathname & file_r,
-                          const unsigned media_nr = 1);
-    const void releaseDir(const Pathname & dir_r,
-                         const unsigned media_nr = 1,
-                         const bool recursive = false);
+    const void releaseFile(const Pathname & file_r, const unsigned media_nr = 1);
+    const void releaseDir(const Pathname & dir_r, const unsigned media_nr = 1, bool recursive = false);
 
-    const bool enabled() const;
+    bool enabled() const;
 
     void enable();
 
     void disable();
 
-    const bool autorefresh() const;
-    void setAutorefresh( const bool enable_r );
+    bool autorefresh() const;
+    void setAutorefresh( bool enable_r );
     void refresh();
 
     void storeMetadata(const Pathname & cache_dir_r);
@@ -253,7 +248,7 @@ namespace zypp
     void setUrl( const Url & url );
     bool remote() const;
     const Pathname & path (void) const;
-    const bool baseSource() const;
+    bool baseSource() const;
     //@}
 
   public:
index f383f1b..8c60791 100644 (file)
@@ -43,12 +43,11 @@ namespace zypp
       static Source_Ref::Impl_Ptr createSourceImpl( const media::MediaId & media_r,
                                                     const SourceInfo &context )
       {
-        MIL << "pre pass type: " << _SourceImpl::typeString() << endl;
         Source_Ref::Impl_Ptr impl( new _SourceImpl );
-        MIL << "pass type: " << _SourceImpl::typeString() << endl;
         // note, base_source is a tribool, if indeterminate we fallback to false
+        //MIL << "Going to call factory ctor:" << endl;
+        //MIL << context << endl;
         impl->factoryCtor( media_r, context.path(), context.alias(), context.cacheDir(), context.baseSource(), context.autorefresh() );
-        MIL << "pass 2 type: " << _SourceImpl::typeString() << endl;
         return impl;
       }
   };
@@ -159,7 +158,7 @@ namespace zypp
   template<class _SourceImpl>
   Source_Ref SourceFactory::createSourceImplWorkflow( media::MediaId id, const SourceInfo &context )
   {
-    MIL << "Trying (pre) to create source of type " << _SourceImpl::typeString() << endl;
+      //MIL << "Trying (pre) to create source of type " << _SourceImpl::typeString() << endl;
       callback::SendReport<SourceCreateReport> report;
       bool retry = true;
       while (retry)
@@ -320,11 +319,13 @@ namespace zypp
       MIL << "Initializing from cache" << endl;
     }
 
+    bool calculated_autorefresh = auto_refresh;
     // Sane default for unknown autorefresh
     if ( auto_refresh == indeterminate )
-      auto_refresh = media::MediaAccess::canBeVolatile( url_r );
+      calculated_autorefresh = media::MediaAccess::canBeVolatile( url_r );
 
-    SourceInfo context( url_r, path_r, alias_r, cache_dir_r, auto_refresh );
+    //SourceInfo( url, path, alias, cache_dir, autorefresh );
+    SourceInfo context( url_r, path_r, alias_r, cache_dir_r, calculated_autorefresh );
     context.setBaseSource( base_source );
     context.setType( type );
     
index 668004b..2f77cb3 100644 (file)
@@ -335,37 +335,36 @@ namespace zypp
   */
   bool SourceManager::restore( Pathname root_r, bool use_caches, const std::string &alias_filter, const std::string &url_filter )
   {
-    MIL << "SourceManager restore ('" << root_r << ( use_caches ? "' (use_caches)" : "'" )
-       << ", alias_filter '" << alias_filter
-       << ", url_filter '" << url_filter << "')" << endl;
+    MIL << "SourceManager restore ('" << root_r << ( use_caches ? "' (use_caches)" : "'" ) << ", alias_filter '" << alias_filter << ", url_filter '" << url_filter << "')" << endl;
 
-    if (! _sources.empty() ) {
+    if (! _sources.empty() )
+    {
 
-       // if we've already restored sources and this is an unfiltered call, reject it.
+      // if we've already restored sources and this is an unfiltered call, reject it.
 
-       if (alias_filter.empty()
-           && url_filter.empty())
-       {
-           ZYPP_THROW(SourcesAlreadyRestoredException());
-           //Exception ( N_("At least one source already registered, cannot restore sources from persistent store.") ) );
-       }
+      if (alias_filter.empty()
+      && url_filter.empty())
+      {
+        ZYPP_THROW(SourcesAlreadyRestoredException());
+        //Exception ( N_("At least one source already registered, cannot restore sources from persistent store.") ) );
+      }
 
-       // check filters against already restore sources and check for duplicates.
-       //
-       for (SourceMap::const_iterator it = _sources.begin(); it != _sources.end(); ++it) {
-           if (!alias_filter.empty()
-               && (alias_filter == it->second.alias()) )
-           {
-               MIL << "Source with alias '" << alias_filter << "' already restored.";
-               return true;
-           }
-           if (!url_filter.empty()
-               && (url_filter == it->second.url().asString()) )
-           {
-               MIL << "Source with url '" << url_filter << "' already restored.";
-               return true;
-           }
-       }
+      // check filters against already restore sources and check for duplicates.
+      //
+      for (SourceMap::const_iterator it = _sources.begin(); it != _sources.end(); ++it)
+      {
+        if (!alias_filter.empty() && (alias_filter == it->second.alias()) )
+        {
+          MIL << "Source with alias '" << alias_filter << "' already restored.";
+          return true;
+        }
+        
+        if (!url_filter.empty() && (url_filter == it->second.url().asString()) )
+        {
+          MIL << "Source with url '" << url_filter << "' already restored.";
+          return true;
+        }
+      }
     }
 
     FailedSourcesRestoreException report;
@@ -379,85 +378,86 @@ namespace zypp
 
     for( std::list<source::SourceInfo>::iterator it = new_sources.begin(); it != new_sources.end(); ++it)
     {
-       if ( !alias_filter.empty()                      // check alias filter, if set
-             && (alias_filter != it->alias()) )
-       {
-           continue;
-       }
+      if ( !alias_filter.empty()                       // check alias filter, if set
+           && (alias_filter != it->alias()) )
+      {
+        continue;
+      }
 
-       if ( !url_filter.empty()                        // check url filter, if set
+      if ( !url_filter.empty()                 // check url filter, if set
                      && (url_filter != it->url().asString()) )
-       {
-           continue;
-       }
+      {
+        continue;
+      }
+
+      // 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() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
 
-       // 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() << "] auto_refresh:[ " << it->autorefresh() << "]" << endl;
-  
-         SourceId id = 0;
-  
-         try {
-            id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir(), false, it->autorefresh()) );
-         }
-         catch (const Exception &expt )
-         {
-             // Note: Url(it->url).asString() to hide password in logs
-            ERR << "Unable to restore source from " << it->url().asString()
-                 << endl;
-  
-             id = 0;
-             Url url2;
-             try {
-                url2 = it->url();
-                 std::string scheme( url2.getScheme());
-  
-                 if( (scheme == "cd" || scheme == "dvd") &&
-                     !url2.getQueryParam("devices").empty())
-                 {
-                     url2.setQueryParam("devices", "");
-  
-                     DBG << "CD/DVD devices changed - try again without a devices list"
-                         << std::endl;
-  
-                      id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir(), false ) );
-  
-                     // This worked ... update it->url ?
-                     //it->url = url2.asCompleteString();
-                 }
-             }
-             catch (const Exception &e2)
-             {
-                 // Note: Url(it->url).asString() to hide password in logs
-                 ERR << "Unable to restore source from " << url2.asString()
-                     << endl;
-                 id = 0;
-                 ZYPP_CAUGHT(e2);
-             }
-  
-             if( id == 0)
-             {
-                report.append( it->url().asString() + it->path().asString(), it->alias(), expt );
-                 continue;
-             }
-         }
-  
-         DBG << "Added source as id " << id << endl;
-         // should not throw, we've just created the source
-         Source_Ref src = findSource( id );
-  
-          if ( it->enabled() ) {
-             DBG << "enable source" << endl;
-             src.enable();
-         }
-         else {
-             DBG << "disable source" << endl;
-             src.disable();
-         }
+      SourceId id = 0;
+
+      try
+      {
+          Source_Ref src = SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir(), false, it->autorefresh());
+          id = addSource(src); 
+      }
+      catch (const Exception &expt )
+      {
+        // Note: Url(it->url).asString() to hide password in logs
+        ERR << "Unable to restore source from " << it->url().asString() << endl;
+
+        id = 0;
+        Url url2;
+        try
+        {
+          url2 = it->url();
+          std::string scheme( url2.getScheme());
+
+          if( (scheme == "cd" || scheme == "dvd") && !url2.getQueryParam("devices").empty())
+          {
+            url2.setQueryParam("devices", "");
+            DBG << "CD/DVD devices changed - try again without a devices list" << std::endl;
+
+            id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir(), false ) );
+
+            // This worked ... update it->url ?
+            //it->url = url2.asCompleteString();
+          }
+        }
+        catch (const Exception &e2)
+        {
+          // Note: Url(it->url).asString() to hide password in logs
+          ERR << "Unable to restore source from " << url2.asString()
+              << endl;
+          id = 0;
+          ZYPP_CAUGHT(e2);
+        }
+
+        if( id == 0)
+        {
+          report.append( it->url().asString() + it->path().asString(), it->alias(), expt );
+          continue;
+        }
+      }
+
+      DBG << "Added source as id " << id << endl;
+      // should not throw, we've just created the source
+      Source_Ref src = findSource( id );
+
+      if ( it->enabled() )
+      {
+        DBG << "enable source" << endl;
+        src.enable();
+      }
+      else
+      {
+        DBG << "disable source" << endl;
+        src.disable();
+      }
     }
 
     if( !report.empty() )
     {
-       ZYPP_THROW(report);
+      ZYPP_THROW(report);
     }
 
     MIL << "SourceManager restore done." << endl;
index 326bf42..8418375 100644 (file)
@@ -73,7 +73,7 @@ namespace xmlstore {
             {
               if ( (_helper.content(child) == "true") || (_helper.content(child) == "1") )
                 dataPtr->setAutorefresh(true);
-              if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") )
+              else if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") )
                 dataPtr->setAutorefresh(false);
               else
                 dataPtr->setAutorefresh(boost::indeterminate);
index 992ff4a..54ebc87 100644 (file)
@@ -155,7 +155,7 @@ namespace zypp
                                   const Pathname & path_r,
                                   const std::string & alias_r,
                                   const Pathname cache_dir_r,
-                                 bool base_source,
+                                  bool base_source,
                                   bool auto_refresh )
     {
       _media_set = new MediaSet( selfSourceRef() );
@@ -166,6 +166,8 @@ namespace zypp
       _cache_dir = cache_dir_r;
       _subscribed = true;
       _base_source = base_source;
+      
+      MIL << "Setting autorefresh: " << auto_refresh << endl;
       _autorefresh = auto_refresh;
 
       try
@@ -202,6 +204,27 @@ namespace zypp
       }
     }
 
+      bool SourceImpl::enabled() const
+      {
+        return _enabled;
+      }
+
+      void SourceImpl::disable()
+      {
+        _enabled = false;
+      }
+
+      bool SourceImpl::autorefresh() const
+      {
+        return _autorefresh;
+      }
+
+      void SourceImpl::setAutorefresh( bool enable )
+      {
+        MIL << "Changing source [" << alias() << "] [" << url() << "] to autorefresh: " << enable << endl;
+        _autorefresh = enable;
+      }
+    
     const ResStore & SourceImpl::resolvables() const
     {
       if ( !_res_store_initialized )
@@ -858,6 +881,9 @@ namespace zypp
           << _url << "(" << _path << ")";
       if ( ! _cache_dir.empty() )
         str << "; cache " << _cache_dir;
+      
+      str << "; autorefresh: " << _autorefresh;
+      str << "; enabled: " << _enabled;
       str << "}";
 
       return str;
index 2cfd794..319fb73 100644 (file)
@@ -189,20 +189,11 @@ namespace zypp
 
       void changeMedia(const media::MediaId & media_r, const Pathname & path_r);
 
-      const bool enabled() const
-      { return _enabled; }
-
+      bool enabled() const;
       void enable();
-
-      void disable()
-      { _enabled = false; }
-
-      const bool autorefresh() const
-      { return _autorefresh; }
-
-      void setAutorefresh( const bool enable_r )
-      { _autorefresh = enable_r; }
-
+      void disable();
+      bool autorefresh() const;
+      void setAutorefresh( bool enable_r );
       void refresh();
 
       virtual void storeMetadata(const Pathname & cache_dir_r);
index 136a754..1d0bba7 100644 (file)
@@ -112,7 +112,7 @@ namespace source
   { return _enabled; }
 
   tribool SourceInfo::autorefresh() const
-  { return _enabled; }
+  { return _autorefresh; }
 
   boost::tribool SourceInfo::baseSource() const
   { return _base_source; }
index c3a14c1..d75a501 100644 (file)
@@ -580,7 +580,6 @@ namespace zypp
           MIL << "Read product: " << _product->summary() << endl;
 
           _prodImpl = p.prodImpl;
-          _autorefresh = p.volatile_content && media::MediaAccess::canBeVolatile( _url );
         }
         catch ( const Exception & e ) {
           ZYPP_THROW (SourceMetadataException("Cannot parse content file: " + e.msg()));