From: Jan Kupec Date: Tue, 29 Jul 2008 15:54:30 +0000 (+0000) Subject: - RepoInfoBase added for common SericeInfo and RepoInfo stuff X-Git-Tag: BASE-SuSE-Code-11-Branch~559 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2972e5755d316b45906ed9b1db671d7ea69693a;p=platform%2Fupstream%2Flibzypp.git - RepoInfoBase added for common SericeInfo and RepoInfo stuff --- diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index d7cbd62..840c414 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -705,6 +705,7 @@ SET( zypp_repo_SRCS repo/MediaInfoDownloader.cc repo/Downloader.cc repo/RepoVariables.cc + repo/RepoInfoBase.cc ) SET( zypp_repo_HEADERS @@ -720,6 +721,8 @@ SET( zypp_repo_HEADERS repo/MediaInfoDownloader.h repo/Downloader.h repo/RepoVariables.h + repo/RepoInfoBase.h + repo/RepoInfoBaseImpl.h ) INSTALL( FILES diff --git a/zypp/RepoInfo.cc b/zypp/RepoInfo.cc index 07d67f6..854108f 100644 --- a/zypp/RepoInfo.cc +++ b/zypp/RepoInfo.cc @@ -16,6 +16,7 @@ #include "zypp/media/MediaAccess.h" #include "zypp/RepoInfo.h" +#include "zypp/repo/RepoInfoBaseImpl.h" using namespace std; @@ -28,29 +29,18 @@ namespace zypp // CLASS NAME : RepoInfo::Impl // /** RepoInfo implementation. */ - struct RepoInfo::Impl + struct RepoInfo::Impl : public repo::RepoInfoBase::Impl { - enum FlagsDeterminedState - { - FLAG_ENABLED = 1, - FLAG_AUTOREFRESH = 2, - FLAG_GPGCHECK = 4, - FLAG_KEEPPACKAGES = 8 - }; - Impl() - : enabled (false), - autorefresh(false), - gpgcheck(true), - keeppackages(false), - type(repo::RepoType::NONE_e), - flags_determined(0) + : repo::RepoInfoBase::Impl() + , gpgcheck(indeterminate) + , keeppackages(indeterminate) + , type(repo::RepoType::NONE_e) {} ~Impl() - { - //MIL << std::endl; - } + {} + public: static const unsigned defaultPriority = 99; @@ -65,24 +55,17 @@ namespace zypp } public: - bool enabled; - bool autorefresh; - bool gpgcheck; - bool keeppackages; + TriBool gpgcheck; + TriBool keeppackages; Url gpgkey_url; repo::RepoType type; Url mirrorlist_url; std::set baseUrls; Pathname path; - std::string alias; - std::string escaped_alias; - std::string name; std::string service; - Pathname filepath; Pathname metadatapath; Pathname packagespath; DefaultIntegral priority; - int flags_determined; public: private: @@ -134,25 +117,9 @@ namespace zypp return *this; } - - RepoInfo & RepoInfo::setEnabled( bool enabled ) - { - _pimpl->enabled = enabled; - _pimpl->flags_determined |= Impl::FLAG_ENABLED; - return *this; - } - - RepoInfo & RepoInfo::setAutorefresh( bool autorefresh ) - { - _pimpl->autorefresh = autorefresh; - _pimpl->flags_determined |= Impl::FLAG_AUTOREFRESH; - return *this; - } - RepoInfo & RepoInfo::setGpgCheck( bool check ) { _pimpl->gpgcheck = check; - _pimpl->flags_determined |= Impl::FLAG_GPGCHECK; return *this; } @@ -170,18 +137,6 @@ namespace zypp RepoInfo & RepoInfo::addBaseUrl( const Url &url ) { - // set only if not already set externally (bnc #394728) - if (!(_pimpl->flags_determined & Impl::FLAG_KEEPPACKAGES) && - _pimpl->baseUrls.empty()) - { - if ( media::MediaAccess::downloads( url ) ) - // don't do this via setKeepPackages, it would set the flags_determined - // for FLAG_KEEPPACKAGES - _pimpl->keeppackages = true; - else - _pimpl->keeppackages = false; - } - _pimpl->baseUrls.insert(url); return *this; } @@ -199,23 +154,6 @@ namespace zypp return *this; } - RepoInfo & RepoInfo::setAlias( const std::string &alias ) - { - _pimpl->alias = alias; - // replace slashes with underscores - std::string fnd="/"; - std::string rep="_"; - std::string escaped_alias = alias; - size_t pos = escaped_alias.find(fnd); - while(pos!=string::npos) - { - escaped_alias.replace(pos,fnd.length(),rep); - pos = escaped_alias.find(fnd,pos+rep.length()); - } - _pimpl->escaped_alias = escaped_alias; - return *this; - } - RepoInfo & RepoInfo::setType( const repo::RepoType &t ) { _pimpl->type = t; @@ -225,17 +163,6 @@ namespace zypp void RepoInfo::setProbedType( const repo::RepoType &t ) const { _pimpl->setProbedType( t ); } - RepoInfo & RepoInfo::setName( const std::string &name ) - { - _pimpl->name = name; - return *this; - } - - RepoInfo & RepoInfo::setFilepath( const Pathname &filepath ) - { - _pimpl->filepath = filepath; - return *this; - } RepoInfo & RepoInfo::setMetadataPath( const Pathname &path ) { @@ -252,7 +179,6 @@ namespace zypp RepoInfo & RepoInfo::setKeepPackages( bool keep ) { _pimpl->keeppackages = keep; - _pimpl->flags_determined |= Impl::FLAG_KEEPPACKAGES; return *this; } @@ -262,34 +188,8 @@ namespace zypp return *this; } - bool RepoInfo::enabled() const - { return _pimpl->enabled; } - - bool RepoInfo::autorefresh() const - { return _pimpl->autorefresh; } - bool RepoInfo::gpgCheck() const - { return _pimpl->gpgcheck; } - - std::string RepoInfo::alias() const - { return _pimpl->alias; } - - std::string RepoInfo::escaped_alias() const - { return _pimpl->escaped_alias; } - - std::string RepoInfo::name() const - { - if ( _pimpl->name.empty() ) - { - return alias(); - } - - repo::RepoVariablesStringReplacer replacer; - return replacer(_pimpl->name); - } - - Pathname RepoInfo::filepath() const - { return _pimpl->filepath; } + { return indeterminate(_pimpl->gpgcheck) ? true : (bool) _pimpl->gpgcheck; } Pathname RepoInfo::metadataPath() const { return _pimpl->metadatapath; } @@ -347,13 +247,26 @@ namespace zypp bool RepoInfo::baseUrlsEmpty() const { return _pimpl->baseUrls.empty(); } + // false by default (if not set by setKeepPackages) bool RepoInfo::keepPackages() const - { return _pimpl->keeppackages; } + { + if (indeterminate(_pimpl->keeppackages)) + { + if (_pimpl->baseUrls.empty()) + return false; + else if ( media::MediaAccess::downloads( *baseUrlsBegin() ) ) + return true; + else + return false; + } + + return (bool) _pimpl->keeppackages; + } + std::ostream & RepoInfo::dumpOn( std::ostream & str ) const { - str << "--------------------------------------" << std::endl; - str << "- alias : " << alias() << std::endl; + RepoInfoBase::dumpOn(str); for ( urls_const_iterator it = baseUrlsBegin(); it != baseUrlsEnd(); ++it ) @@ -362,10 +275,8 @@ namespace zypp } str << "- path : " << path() << std::endl; str << "- type : " << type() << std::endl; - str << "- enabled : " << enabled() << std::endl; str << "- priority : " << priority() << std::endl; - str << "- autorefresh : " << autorefresh() << std::endl; str << "- gpgcheck : " << gpgCheck() << std::endl; str << "- gpgkey : " << gpgKeyUrl() << std::endl; str << "- keeppackages: " << keepPackages() << std::endl; @@ -376,9 +287,7 @@ namespace zypp std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const { - // we save the original data without variable replacement - str << "[" << alias() << "]" << endl; - str << "name=" << _pimpl->name << endl; + RepoInfoBase::dumpAsIniOn(str); if ( ! _pimpl->baseUrls.empty() ) str << "baseurl="; @@ -396,17 +305,17 @@ namespace zypp str << "mirrorlist=" << _pimpl->mirrorlist_url << endl; str << "type=" << type().asString() << endl; - str << "enabled=" << (enabled() ? "1" : "0") << endl; if ( priority() != defaultPriority() ) str << "priority=" << priority() << endl; - str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl; - str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl; + if (!indeterminate(_pimpl->gpgcheck)) + str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl; if ( ! (gpgKeyUrl().asString().empty()) ) str << "gpgkey=" <.repo file format. */ - std::ostream & dumpRepoOn( std::ostream & str ) const; + virtual std::ostream & dumpRepoOn( std::ostream & str ) const; class Impl; private: diff --git a/zypp/repo/RepoInfoBase.cc b/zypp/repo/RepoInfoBase.cc new file mode 100644 index 0000000..95a1913 --- /dev/null +++ b/zypp/repo/RepoInfoBase.cc @@ -0,0 +1,158 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/repo/RepoInfoBase.cc + * + */ +#include + +#include "zypp/repo/RepoInfoBase.h" +#include "zypp/repo/RepoInfoBaseImpl.h" + +using namespace std; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace repo + { ///////////////////////////////////////////////////////////////// + + + /** \relates RepoInfo::Impl Stream output */ + inline std::ostream & operator<<( std::ostream & str, const RepoInfoBase::Impl & obj ) + { + return str << "RepoInfo::Impl"; + } + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : RepoInfoBase + // + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : RepoInfo::RepoInfo + // METHOD TYPE : Ctor + // + RepoInfoBase::RepoInfoBase() + : _pimpl( new Impl() ) + {} + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : RepoInfoBase::~RepoInfoBase + // METHOD TYPE : Dtor + // + RepoInfoBase::~RepoInfoBase() + {} + + RepoInfoBase & RepoInfoBase::setEnabled( bool enabled ) + { + _pimpl->enabled = enabled; + return *this; + } + + RepoInfoBase & RepoInfoBase::setAutorefresh( bool autorefresh ) + { + _pimpl->autorefresh = autorefresh; + return *this; + } + + RepoInfoBase & RepoInfoBase::setAlias( const std::string &alias ) + { + _pimpl->alias = alias; + // replace slashes with underscores + std::string fnd="/"; + std::string rep="_"; + std::string escaped_alias = alias; + size_t pos = escaped_alias.find(fnd); + while(pos!=string::npos) + { + escaped_alias.replace(pos,fnd.length(),rep); + pos = escaped_alias.find(fnd,pos+rep.length()); + } + _pimpl->escaped_alias = escaped_alias; + return *this; + } + + RepoInfoBase & RepoInfoBase::setName( const std::string &name ) + { + _pimpl->name = name; + return *this; + } + + RepoInfoBase & RepoInfoBase::setFilepath( const Pathname &filepath ) + { + _pimpl->filepath = filepath; + return *this; + } + + // true by default (if not set by setEnabled()) + bool RepoInfoBase::enabled() const + { return indeterminate(_pimpl->enabled) ? true : (bool) _pimpl->enabled; } + + // false by default (if not set by setAutorefresh()) + bool RepoInfoBase::autorefresh() const + { return indeterminate(_pimpl->autorefresh) ? false : (bool) _pimpl->autorefresh; } + + std::string RepoInfoBase::alias() const + { return _pimpl->alias; } + + std::string RepoInfoBase::escaped_alias() const + { return _pimpl->escaped_alias; } + + std::string RepoInfoBase::name() const + { + if ( _pimpl->name.empty() ) + { + return alias(); + } + + //! \todo repo::RepoVariablesStringReplacer replacer; + return _pimpl->name; //replacer(_pimpl->name); + } + + Pathname RepoInfoBase::filepath() const + { return _pimpl->filepath; } + + + std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const + { + str << "--------------------------------------" << std::endl; + str << "- alias : " << alias() << std::endl; + str << "- alias : " << name() << std::endl; + str << "- enabled : " << enabled() << std::endl; + str << "- autorefresh : " << autorefresh() << std::endl; + + return str; + } + + std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const + { + // we save the original data without variable replacement + str << "[" << alias() << "]" << endl; + str << "name=" << name() << endl; + str << "enabled=" << (enabled() ? "1" : "0") << endl; + str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl; + + return str; + } + + std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj ) + { + return obj.dumpOn(str); + } + + ///////////////////////////////////////////////////////////////// + } // namespace repo + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/repo/RepoInfoBase.h b/zypp/repo/RepoInfoBase.h new file mode 100644 index 0000000..d6738ea --- /dev/null +++ b/zypp/repo/RepoInfoBase.h @@ -0,0 +1,158 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/repo/RepoInfoBase.h + * + */ +#ifndef REPOINFOBASE_H_ +#define REPOINFOBASE_H_ + +#include + +#include "zypp/base/PtrTypes.h" + +#include "zypp/Pathname.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace repo + { ///////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : RepoInfoBase + // + /** + * \short Base class implementing common features of \ref RepoInfo and + * \ref ServiceInfo. + */ + class RepoInfoBase + { + friend std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj ); + + public: + RepoInfoBase(); + ~RepoInfoBase(); + + /** + * unique identifier for this source. If not specified + * It should be generated from the base url. + * + * Normally, in a .repo file the section name is used + * ( [somerepo] ) + */ + std::string alias() const; + + /** + * Same as alias(), just escaped in a way to be a valid file name. + */ + std::string escaped_alias() const; + + /** + * \short Repository short label + * + * Short label or description of the repository, to be used on + * the user interface. + * ie: "SUSE Linux 10.2 updates" + */ + std::string name() const; + + /** + * If enabled is false, then this repository must be ignored as if does + * not exists, except when checking for duplicate alias. + */ + bool enabled() const; + + /** + * If true, the repostory must be refreshed before creating resolvables + * from it + */ + bool autorefresh() const; + + /** + * \short File where this repo was read from + * + * \note could be an empty pathname for repo + * infos created in memory. + */ + Pathname filepath() const; + + + public: + + /** + * set the repository alias \see alias + * \param alias + */ + RepoInfoBase & setAlias( const std::string &alias ); + + /** + * set the repository name \see name + * \param name + */ + RepoInfoBase & setName( const std::string &name ); + + /** + * enable or disable the repository \see enabled + * \param enabled + */ + RepoInfoBase & setEnabled( bool enabled ); + + /** + * enable or disable autorefresh \see autorefresh + * \param enabled + */ + RepoInfoBase & setAutorefresh( bool autorefresh ); + + /** + * \short set the path to the .repo file + * + * The path to the .repo file where this repository + * was defined, or empty if nowhere. + * + * \param path File path + */ + RepoInfoBase & setFilepath( const Pathname &filename ); + + /** + * Write a human-readable representation of this RepoInfoBase object + * into the \a str stream. Useful for logging. + */ + virtual std::ostream & dumpOn( std::ostream & str ) const; + + /** + * Write this RepoInfoBase object into \a str in + * a .repo (ini) file format. + */ + virtual std::ostream & dumpAsIniOn( std::ostream & str ) const; + + class Impl; + private: + /** Pointer to implementation */ + RWCOW_pointer _pimpl; + }; + /////////////////////////////////////////////////////////////////// + + /** \relates RepoInfoBase Stream output */ + std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj ); + + inline bool operator<( const RepoInfoBase & lhs, const RepoInfoBase & rhs ) + { return lhs.alias() < rhs.alias(); } + + + ///////////////////////////////////////////////////////////////// + } // namespace repo + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// + +#endif /*REPOINFOBASE_H_*/ diff --git a/zypp/repo/RepoInfoBaseImpl.h b/zypp/repo/RepoInfoBaseImpl.h new file mode 100644 index 0000000..28ff662 --- /dev/null +++ b/zypp/repo/RepoInfoBaseImpl.h @@ -0,0 +1,65 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/repo/RepoInfoBaseImpl.h + * + */ +#ifndef REPOINFOBASEIMPL_H_ +#define REPOINFOBASEIMPL_H_ + +#include + +#include "zypp/TriBool.h" +#include "zypp/Pathname.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace repo + { ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : RepoInfoBase::Impl + // + struct RepoInfoBase::Impl + { + Impl() + : enabled (indeterminate) + , autorefresh (indeterminate) + {} + + ~Impl() + {} + + public: + TriBool enabled; + TriBool autorefresh; + std::string alias; + std::string escaped_alias; + std::string name; + Pathname filepath; + public: + + private: + friend Impl * rwcowClone( const Impl * rhs ); + /** clone for RWCOW_pointer */ + Impl * clone() const + { return new Impl( *this ); } + }; + /////////////////////////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////////// + } // namespace repo + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// + +#endif /*REPOINFOBASEIMPL_H_*/ diff --git a/zypp/sat/Pool.cc b/zypp/sat/Pool.cc index 936135c..272cdad 100644 --- a/zypp/sat/Pool.cc +++ b/zypp/sat/Pool.cc @@ -107,11 +107,13 @@ namespace zypp if ( alias_r == systemRepoAlias() ) { // autoprovide (dummy) RepoInfo - ret.setInfo( RepoInfo() - .setAlias( alias_r ) - .setName( alias_r ) - .setAutorefresh( true ) - .setEnabled( true ) ); + RepoInfo info; + info + .setAlias( alias_r ) + .setName( alias_r ) + .setAutorefresh( true ) + .setEnabled( true ); + ret.setInfo( info ); } return ret; }