#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"
#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;
*/
struct OldPMSourceParser : public parser::tagfile::TagFileParser
{
- PersistentStorage::SourceData result;
+ source::SourceInfo result;
virtual void beginParse()
{
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. */
#include "zypp/base/Exception.h"
///////////////////////////////////////////////////////////////////
+#include "zypp/source/SourceInfo.h"
#include "zypp/target/store/PersistentStorage.h"
#include "zypp/target/store/XMLFilesBackend.h"
#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;
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();
}
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;
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"));
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())
#include "zypp/base/PtrTypes.h"
#include "zypp/Source.h"
+#include "zypp/source/SourceInfo.h"
#include "zypp/Url.h"
#include "zypp/Pathname.h"
~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.
*/
{
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("");
}
}
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") &&
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();
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;
}
}
// 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();
}
DBG << "disable source" << endl;
src.disable();
}
- src.setAutorefresh ( it->autorefresh );
+ src.setAutorefresh ( it->autorefresh() );
}
if( !report.empty() )
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 );
}
}
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
{
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");
- }
+
}
/////////////////////////////////////////////////////////////////
#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
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"));
}
//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());
}
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();
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();
}