- adapt everything to SourceInfo with accesors and tribool status
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 26 Jun 2006 09:25:28 +0000 (09:25 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 26 Jun 2006 09:25:28 +0000 (09:25 +0000)
for autorefresh and enabled

testsuite/target/tests/import_old_sources_test.cc
testsuite/target/tests/storagetargettest.cc
zypp/SourceFactory.cc
zypp/SourceFactory.h
zypp/SourceManager.cc
zypp/parser/xmlstore/XMLSourceCacheParser.cc
zypp/source/SourceInfo.cc
zypp/source/SourceInfo.h
zypp/target/store/XMLFilesBackend.cc
zypp/target/store/serialize.cc

index d626dd8..a3d1ce0 100644 (file)
@@ -15,6 +15,7 @@
 #include "zypp/base/Exception.h"
 ///////////////////////////////////////////////////////////////////
 
+#include "zypp/source/SourceInfo.h"
 #include "zypp/target/store/PersistentStorage.h"
 #include "zypp/target/store/XMLFilesBackend.h"
 #include "zypp/parser/tagfile/TagFileParser.h"
@@ -33,9 +34,6 @@
 
 #include "zypp/target/store/serialize.h"
 
-#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
-#include "boost/filesystem/fstream.hpp"    // ditto
-
 using namespace zypp::detail;
 using namespace std;
 using namespace zypp;
@@ -65,7 +63,7 @@ using namespace boost::filesystem;
 */
 struct OldPMSourceParser : public parser::tagfile::TagFileParser
 {
-  PersistentStorage::SourceData result;
+  source::SourceInfo result;
   
   virtual void beginParse()
   {
@@ -74,18 +72,18 @@ struct OldPMSourceParser : public parser::tagfile::TagFileParser
   virtual void consume( const SingleTag & stag_r )
   {
     if ( stag_r.name == "Type" )
-      result.type = stag_r.value;
+      result.setType(stag_r.value);
     if ( stag_r.name == "URL" )
     {
-      result.url = stag_r.value;
-      result.alias = stag_r.value;
+      result.setUrl(stag_r.value);
+      result.setAlias(stag_r.value);
     }
     if ( stag_r.name == "ProductDir" )
-      result.product_dir = stag_r.value;
+      result.setPath(stag_r.value);
     if ( stag_r.name == "Default_activate" )
-      result.enabled = (stag_r.value == "1") ? true : false;
+      result.setEnabled( (stag_r.value == "1") ? true : false );
     if ( stag_r.name == "Default_refresh" )
-      result.autorefresh = (stag_r.value == "1") ? true : false;
+      result.setAutorefresh( (stag_r.value == "1") ? true : false );
   }
   
   /* Consume MulitTag data. */
index 6f6f3db..76bad4d 100644 (file)
@@ -14,6 +14,7 @@
 #include "zypp/base/Exception.h"
 ///////////////////////////////////////////////////////////////////
 
+#include "zypp/source/SourceInfo.h"
 #include "zypp/target/store/PersistentStorage.h"
 #include "zypp/target/store/XMLFilesBackend.h"
 
@@ -36,9 +37,6 @@
 
 #include "zypp/target/store/serialize.h"
 
-#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
-#include "boost/filesystem/fstream.hpp"    // ditto
-
 #include "Benchmark.h"
 
 using namespace zypp::detail;
@@ -106,8 +104,8 @@ struct StorageTargetTest
     if (zyppvar == "/var")
       ZYPP_THROW(Exception("I refuse to delete /var"));
     
-    filesystem::recursive_rmdir( zyppvar );
-    filesystem::recursive_rmdir( zyppcache );
+//    filesystem::recursive_rmdir( zyppvar );
+//    filesystem::recursive_rmdir( zyppcache );
     _store.clear();
   }
   
@@ -192,10 +190,10 @@ struct StorageTargetTest
   void storeKnownSources()
   {
     INT << "===[SOURCES]==========================================" << endl;
-    PersistentStorage::SourceData data;
-    data.url = _source.url().asString();
-    data.type = _source.type();
-    data.alias = _source.alias();
+    source::SourceInfo data;
+    data.setUrl(_source.url());
+    data.setType(_source.type());
+    data.setAlias(_source.alias());
 
     _backend->storeSource(data);
     MIL << "Wrote 1 source" << std::endl;
@@ -247,7 +245,7 @@ struct StorageTargetTest
     clean();
     unpackDatabase("db.tar.gz");
     initStorageBackend();
-    std::list<PersistentStorage::SourceData> sources = _backend->storedSources();
+    source::SourceInfoList sources = _backend->storedSources();
     MIL << "Read " << sources.size() << " sources" << std::endl;
     if ( sources.size() != 2 )
       ZYPP_THROW(Exception("Known Sources read FAILED")); 
index e87665b..19f1bff 100644 (file)
@@ -123,6 +123,11 @@ namespace zypp
     media_mgr.release(id);
   }
 
+  Source_Ref SourceFactory::createFrom( const source::SourceInfo &context )
+  {
+    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 )
   {
     if (! url_r.isValid())
index 50d792e..c09f236 100644 (file)
@@ -19,6 +19,7 @@
 #include "zypp/base/PtrTypes.h"
 
 #include "zypp/Source.h"
+#include "zypp/source/SourceInfo.h"
 #include "zypp/Url.h"
 #include "zypp/Pathname.h"
 
@@ -45,6 +46,11 @@ namespace zypp
     ~SourceFactory();
 
   public:
+    /** Construct source.
+     * \throw EXCEPTION on fail
+     */
+    Source_Ref createFrom( const source::SourceInfo & context );
+    
     /** Construct source from an implementation.
      * Returns Source_Ref::noSource on NULL \a impl_r.
     */
index 1669762..511ffa0 100644 (file)
@@ -294,33 +294,33 @@ namespace zypp
     {
         source::SourceInfo descr;
         
-       descr.url = it->second.url().asCompleteString();
-        descr.enabled = it->second.enabled() ? SourceInfo::Enabled : SourceInfo::Disabled;
-       descr.alias = it->second.alias();
-        descr.autorefresh = it->second.autorefresh() ? SourceInfo::Enabled : SourceInfo::Disabled;
-       descr.type = it->second.type();
-       descr.product_dir = it->second.path();
+        descr.setUrl(it->second.url());
+        descr.setEnabled( it->second.enabled() );
+        descr.setAlias( it->second.alias() );
+        descr.setAutorefresh( it->second.autorefresh() );
+        descr.setType( it->second.type() );
+        descr.setPath( it->second.path() );
 
-       descr.cache_dir = it->second.cacheDir();
+        descr.setCacheDir( it->second.cacheDir() );
 
-       if( metadata_cache && descr.cache_dir.empty() )
+        if( metadata_cache && descr.cacheDir().empty() )
        {
-           if( descr.cache_dir.empty() )
+          if( descr.cacheDir().empty() )
            {
              filesystem::TmpDir newCache( root_r /  ZYPP_METADATA_PREFIX, "Source." );
-             descr.cache_dir = ZYPP_METADATA_PREFIX + newCache.path().basename();
+              descr.setCacheDir( ZYPP_METADATA_PREFIX + newCache.path().basename() ); 
            }
 
-           filesystem::assert_dir ( root_r.asString() + descr.cache_dir );
+            filesystem::assert_dir ( root_r.asString() + descr.cacheDir() );
 
-           MIL << "Storing metadata to (" << root_r.asString() << ")/" << descr.cache_dir << endl;
+            MIL << "Storing metadata to (" << root_r.asString() << ")/" << descr.cacheDir() << endl;
 
            try {
-               it->second.storeMetadata( root_r.asString() + descr.cache_dir );
+              it->second.storeMetadata( root_r.asString() + descr.cacheDir() );
            }
            catch(const Exception &excp) {
                WAR << "Creating local metadata cache failed, not using cache" << endl;
-               descr.cache_dir = "";
+                descr.setCacheDir("");
            }
        }
 
@@ -380,35 +380,35 @@ 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) )
+             && (alias_filter != it->alias()) )
        {
            continue;
        }
 
        if ( !url_filter.empty()                        // check url filter, if set
-           && (url_filter != it->url.asString()) )
+                     && (url_filter != it->url().asString()) )
        {
            continue;
        }
 
        // Note: Url(it->url).asString() to hide password in logs
-       MIL << "Restoring source: url:[" << Url(it->url).asString() << "] product_dir:[" << it->product_dir << "] alias:[" << it->alias << "] cache_dir:[" << it->cache_dir << "]" << endl;
+        MIL << "Restoring source: url:[" << it->url().asString() << "] product_dir:[" << it->path() << "] alias:[" << it->alias() << "] cache_dir:[" << it->cacheDir() << "]" << endl;
   
          SourceId id = 0;
   
          try {
-           id = addSource( SourceFactory().createFrom(it->type, it->url, it->product_dir, it->alias, it->cache_dir) );
+            id = addSource( SourceFactory().createFrom(it->type(), it->url(), it->path(), it->alias(), it->cacheDir()) );
          }
          catch (const Exception &expt )
          {
              // Note: Url(it->url).asString() to hide password in logs
-             ERR << "Unable to restore source from " << Url(it->url).asString()
+            ERR << "Unable to restore source from " << it->url().asString()
                  << endl;
   
              id = 0;
              Url url2;
              try {
-                 url2 = it->url;
+                url2 = it->url();
                  std::string scheme( url2.getScheme());
   
                  if( (scheme == "cd" || scheme == "dvd") &&
@@ -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->product_dir, it->alias, it->cache_dir) );
+                      id = addSource( SourceFactory().createFrom(url2, it->path(), it->alias(), it->cacheDir()) );
   
                      // This worked ... update it->url ?
                      //it->url = url2.asCompleteString();
@@ -436,7 +436,7 @@ namespace zypp
   
              if( id == 0)
              {
-               report.append( it->url.asString() + it->product_dir.asString(), it->alias, expt );
+                report.append( it->url().asString() + it->path().asString(), it->alias(), expt );
                  continue;
              }
          }
@@ -445,7 +445,7 @@ namespace zypp
          // should not throw, we've just created the source
          Source_Ref src = findSource( id );
   
-         if ( it->enabled ) {
+          if ( it->enabled() ) {
              DBG << "enable source" << endl;
              src.enable();
          }
@@ -453,7 +453,7 @@ namespace zypp
              DBG << "disable source" << endl;
              src.disable();
          }
-         src.setAutorefresh ( it->autorefresh );
+          src.setAutorefresh ( it->autorefresh() );
     }
 
     if( !report.empty() )
@@ -478,8 +478,8 @@ namespace zypp
     for( std::list<source::SourceInfo>::iterator it = new_sources.begin();
        it != new_sources.end(); ++it)
     {
-       MIL << "Disabling source " << it->alias << endl;
-        it->enabled = SourceInfo::Disabled;
+        MIL << "Disabling source " << it->alias() << endl;
+        it->setEnabled(false);
        store.storeSource( *it );
     }
   }
index 090cd05..dd4caed 100644 (file)
@@ -63,40 +63,36 @@ namespace xmlstore {
             if (name == "enabled")
             {
               if ( _helper.content(child) == "true" )
-                dataPtr->enabled = source::SourceInfo::Enabled;
-              if ( _helper.content(child) == "false" )
-                dataPtr->enabled = source::SourceInfo::Disabled;
+                dataPtr->setEnabled(true);
               else
-                dataPtr->enabled = source::SourceInfo::NotSet;
+                dataPtr->setEnabled(false);
             }
             else if (name == "auto-refresh")
             {
               if ( _helper.content(child) == "true" )
-                dataPtr->autorefresh = source::SourceInfo::Enabled;
-              if ( _helper.content(child) == "false" )
-                dataPtr->autorefresh = source::SourceInfo::Disabled;
+                dataPtr->setAutorefresh(true);
               else
-                dataPtr->autorefresh = source::SourceInfo::NotSet;
+                dataPtr->setAutorefresh(false);
             }
             else if (name == "type")
             {
-              dataPtr->type = _helper.content(child);
+              dataPtr->setType(_helper.content(child));
             }
             else if (name == "product-dir")
             {
-              dataPtr->product_dir = _helper.content(child);
+              dataPtr->setPath(_helper.content(child));
             }
             else if (name == "cache-dir")
             {
-              dataPtr->cache_dir = _helper.content(child);
+              dataPtr->setCacheDir(_helper.content(child));
             }
             else if (name == "alias")
             {
-              dataPtr->alias = _helper.content(child);
+              dataPtr->setAlias(_helper.content(child));
             }
             else if (name == "url")
             {
-              dataPtr->url = _helper.content(child);
+              dataPtr->setUrl(_helper.content(child));
             }
             else
             {
index d79b53c..5074fc4 100644 (file)
@@ -19,15 +19,7 @@ namespace zypp
 namespace source
 {
   
-  std::ostream & operator<<( std::ostream & str, const SourceInfo::EnabledState & obj )
-  {
-    if ( obj == SourceInfo::Enabled )
-      return str << std::string("true");
-    if ( obj == SourceInfo::Disabled )
-      return str << std::string("false");
-    else
-      return str << std::string("not-set");
-  }
+  
   
 }
   /////////////////////////////////////////////////////////////////
index f89b314..942ab61 100644 (file)
 
 #include <list>
 
+#include <boost/logic/tribool.hpp>
 #include "zypp/Pathname.h"
 #include "zypp/Url.h"
 
+using namespace boost;
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 namespace source
 {
   
-  struct SourceInfo
+  class SourceInfo
   {
-    enum EnabledState {
-      Enabled,
-      Disabled,
-      NotSet
-    };
-    
+    public:
+      
     SourceInfo() :
-        enabled (NotSet),
-        autorefresh(NotSet)
+        _enabled (indeterminate),
+        _autorefresh(indeterminate)
     {
       
-    };
-    
-    EnabledState enabled;
-    EnabledState autorefresh;
-    Pathname product_dir;
-    std::string type;
-    Url url;
-    Pathname cache_dir;
-    std::string alias;
+    }
+    
+    SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", tribool autorefresh = indeterminate)
+      : _enabled (true),
+    _autorefresh(autorefresh),
+    _url(url),
+    _cache_dir(cache_dir),
+    _path(path),
+    _alias(alias)
+    {
+      
+    }
+    
+    SourceInfo & setEnabled( bool enabled )
+    {
+      _enabled = enabled;
+      return *this;
+    }
+    
+    SourceInfo & setAutorefresh( bool autorefresh )
+    {
+      _autorefresh = autorefresh;
+      return *this;
+    }
+    
+    SourceInfo & setUrl( const Url &url )
+    {
+      _url = url;
+      return *this;
+    }
+    
+    SourceInfo & setPath( const Pathname &p )
+    {
+      _path = p;
+      return *this;
+    }
+    
+    SourceInfo & setAlias( const std::string &alias )
+    {
+      _alias = alias;
+      return *this;
+    }
+    
+    SourceInfo & setType( const std::string &t )
+    {
+      _type = t;
+      return *this;
+    }
+    
+    SourceInfo & setCacheDir( const Pathname &p )
+    {
+      _cache_dir = p;
+      return *this;
+    }
+     
+    tribool enabled() const
+    { return _enabled; }
+        
+    tribool autorefresh() const
+    { return _enabled; }    
+    
+    Pathname cacheDir() const
+    { return _cache_dir; }
+    
+    Pathname path() const
+    { return _path; }
+    
+    std::string alias() const
+    { return _alias; }
+    
+    std::string type() const
+    { return _type; }
+    
+    Url url() const
+    { return _url; }
+    
+    private:
+    
+    tribool _enabled;
+    tribool _autorefresh;
+    std::string _type;
+    Url _url;
+    Pathname _cache_dir;
+    Pathname _path;
+    std::string _alias;
   };  
   
-  std::ostream & operator<<( std::ostream & str, const SourceInfo::EnabledState & obj );
   typedef std::list<SourceInfo> SourceInfoList;
-  
 }
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
index ed435eb..58aa73d 100644 (file)
@@ -1241,7 +1241,7 @@ XMLFilesBackend::storeSource(const source::SourceInfo &data)
   path source_p = path(d->root.asString()) / path(ZYPP_DB_DIR) / path ("sources");
 
   // generate a filename
-  if (data.alias.size() == 0)
+  if (data.alias().size() == 0)
   {
     ZYPP_THROW(Exception("Cant save source with empty alias"));
   }
@@ -1251,7 +1251,7 @@ XMLFilesBackend::storeSource(const source::SourceInfo &data)
   //DBG << filename << std::endl;
   try
   {
-    std::stringstream message_stream(data.alias);
+    std::stringstream message_stream(data.alias());
     std::string full_path = (source_p / Digest::digest("MD5", message_stream)).string();
 
     file.open(full_path.c_str());
@@ -1260,7 +1260,7 @@ XMLFilesBackend::storeSource(const source::SourceInfo &data)
   }
   catch ( std::exception &e )
   {
-    ERR << "Error saving source " << data.alias << " in the cache" << std::endl;
+    ERR << "Error saving source " << data.alias() << " in the cache" << std::endl;
     ZYPP_THROW(Exception(e.what()));
   }
   updateTimestamp();
index 18aa051..9be727a 100644 (file)
@@ -436,13 +436,13 @@ std::string toXML( const source::SourceInfo &obj )
   stringstream out;
   out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
   out << "<source  xmlns=\"http://www.novell.com/metadata/zypp/xml-store\">" << std::endl;
-  out << "  <enabled>" << obj.enabled << "</enabled>" << std::endl;
-  out << "  <auto-refresh>" << obj.autorefresh << "</auto-refresh>" << std::endl;
-  out << "  <product-dir>" << obj.product_dir << "</product-dir>" << std::endl;
-  out << "  <cache-dir>" << obj.cache_dir << "</cache-dir>" << std::endl;
-  out << "  <type>" << xml_escape(obj.type) << "</type>" << std::endl;
-  out << "  <url>" << xml_escape(obj.url.asCompleteString()) << "</url>" << std::endl;
-  out << "  <alias>" << xml_escape(obj.alias) << "</alias>" << std::endl;
+  out << "  <enabled>" << obj.enabled() << "</enabled>" << std::endl;
+  out << "  <auto-refresh>" << obj.autorefresh() << "</auto-refresh>" << std::endl;
+  out << "  <product-dir>" << obj.path() << "</product-dir>" << std::endl;
+  out << "  <cache-dir>" << obj.cacheDir() << "</cache-dir>" << std::endl;
+  out << "  <type>" << xml_escape(obj.type()) << "</type>" << std::endl;
+  out << "  <url>" << xml_escape(obj.url().asCompleteString()) << "</url>" << std::endl;
+  out << "  <alias>" << xml_escape(obj.alias()) << "</alias>" << std::endl;
   out << "</source>" << std::endl;
   return out.str();
 }