repo/MediaInfoDownloader.cc
repo/Downloader.cc
repo/RepoVariables.cc
+ repo/RepoInfoBase.cc
)
SET( zypp_repo_HEADERS
repo/MediaInfoDownloader.h
repo/Downloader.h
repo/RepoVariables.h
+ repo/RepoInfoBase.h
+ repo/RepoInfoBaseImpl.h
)
INSTALL( FILES
#include "zypp/media/MediaAccess.h"
#include "zypp/RepoInfo.h"
+#include "zypp/repo/RepoInfoBaseImpl.h"
using namespace std;
// 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;
}
public:
- bool enabled;
- bool autorefresh;
- bool gpgcheck;
- bool keeppackages;
+ TriBool gpgcheck;
+ TriBool keeppackages;
Url gpgkey_url;
repo::RepoType type;
Url mirrorlist_url;
std::set<Url> baseUrls;
Pathname path;
- std::string alias;
- std::string escaped_alias;
- std::string name;
std::string service;
- Pathname filepath;
Pathname metadatapath;
Pathname packagespath;
DefaultIntegral<unsigned,defaultPriority> priority;
- int flags_determined;
public:
private:
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;
}
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;
}
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;
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 )
{
RepoInfo & RepoInfo::setKeepPackages( bool keep )
{
_pimpl->keeppackages = keep;
- _pimpl->flags_determined |= Impl::FLAG_KEEPPACKAGES;
return *this;
}
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; }
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 )
}
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;
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=";
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=" <<gpgKeyUrl() << endl;
- str << "keeppackages=" << keepPackages() << endl;
+ if (!indeterminate(_pimpl->keeppackages))
+ str << "keeppackages=" << keepPackages() << endl;
if( ! service().empty() )
str << "service=" << service() << endl;
#ifndef ZYPP2_REPOSITORYINFO_H
#define ZYPP2_REPOSITORYINFO_H
-#include <iosfwd>
#include <list>
#include <set>
-#include "zypp/base/PtrTypes.h"
+
#include "zypp/base/Iterator.h"
#include "zypp/base/Deprecated.h"
-#include "zypp/Pathname.h"
#include "zypp/Url.h"
#include "zypp/repo/RepoType.h"
#include "zypp/repo/RepoVariables.h"
+#include "zypp/repo/RepoInfoBase.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
* \note A RepoInfo is a hint about how
* to create a Repository.
*/
- class RepoInfo
+ class RepoInfo : public repo::RepoInfoBase
{
friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
~RepoInfo();
/**
- * 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;
-
- /**
* Repository priority for solver.
* Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
*/
*/
bool baseUrlsEmpty() 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;
-
/**
* Type of repository,
*
repo::RepoType type() 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;
-
- /**
- * \short File where this repo was read from
- *
- * \note could be an empty pathname for repo
- * infos created in memory.
- */
- Pathname filepath() const;
-
- /**
* \short Path where this repo metadata was read from
*
* \note could be an empty pathname for repo
*/
Pathname metadataPath() const;
- /**
+ /**
* \short Path where this repo packages are cached
*/
Pathname packagesPath() const;
- /**
+ /**
* \short Whether to check or not this repository with gpg
*
* \note This is a just a hint to the application and can
RepoInfo & setMirrorListUrl( const Url &url );
/**
- * enable or disable the repository \see enabled
- * \param enabled
- */
- RepoInfo & setEnabled( bool enabled );
-
- /**
- * enable or disable autorefresh \see autorefresh
- * \param enabled
- */
- RepoInfo & setAutorefresh( bool autorefresh );
-
- /**
- * set the repository alias \see alias
- * \param alias
- */
- RepoInfo & setAlias( const std::string &alias );
-
- /**
* set the repository type \see type
* \param t
*/
void setProbedType( const repo::RepoType &t ) const;
/**
- * set the repository name \see name
- * \param name
- */
- RepoInfo & setName( const std::string &name );
-
- /**
- * \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
- */
- RepoInfo & setFilepath( const Pathname &filename );
-
- /**
* \short set the path where the local metadata is stored
*
* The path to the metadata of this repository
* Write a human-readable representation of this RepoInfo object
* into the \a str stream. Useful for logging.
*/
- std::ostream & dumpOn( std::ostream & str ) const;
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
/**
* Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
*/
- std::ostream & dumpRepoOn( std::ostream & str ) const;
+ virtual std::ostream & dumpRepoOn( std::ostream & str ) const;
class Impl;
private:
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/repo/RepoInfoBase.cc
+ *
+ */
+#include <iostream>
+
+#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
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/repo/RepoInfoBase.h
+ *
+ */
+#ifndef REPOINFOBASE_H_
+#define REPOINFOBASE_H_
+
+#include <iosfwd>
+
+#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 <tr>.repo</tt> (ini) file format.
+ */
+ virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
+
+ class Impl;
+ private:
+ /** Pointer to implementation */
+ RWCOW_pointer<Impl> _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_*/
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/repo/RepoInfoBaseImpl.h
+ *
+ */
+#ifndef REPOINFOBASEIMPL_H_
+#define REPOINFOBASEIMPL_H_
+
+#include <string>
+
+#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<Impl>( const Impl * rhs );
+ /** clone for RWCOW_pointer */
+ Impl * clone() const
+ { return new Impl( *this ); }
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace repo
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+
+#endif /*REPOINFOBASEIMPL_H_*/
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;
}