#include "zypp/RepoInfo.h"
#include "zypp/TriBool.h"
#include "zypp/Pathname.h"
-#include "zypp/ZConfig.h"
#include "zypp/repo/RepoMirrorList.h"
#include "zypp/ExternalProgram.h"
#include "zypp/media/MediaAccess.h"
struct RepoInfo::Impl
{
Impl()
- : _gpgCheck( indeterminate )
- , _repoGpgCheck( indeterminate )
- , _pkgGpgCheck( indeterminate )
- , _validRepoSignature( indeterminate )
+ : gpgcheck(indeterminate)
, keeppackages(indeterminate)
, type(repo::RepoType::NONE_e)
, emptybaseurls(false)
{ return !emptybaseurls && !_baseUrls.empty(); }
- const RepoVariablesReplacedUrlList & gpgKeyUrls() const
- { return _gpgKeyUrls; }
-
- RepoVariablesReplacedUrlList & gpgKeyUrls()
- { return _gpgKeyUrls; }
-
void addContent( const std::string & keyword_r )
{ _keywords.insert( keyword_r ); }
return( _keywords.find( keyword_r ) != _keywords.end() );
}
- /** Signature check result needs to be stored/retrieved from _metadatapath.
- * Don't call them from outside validRepoSignature/setValidRepoSignature
- */
- //@{
- TriBool internalValidRepoSignature() const
- {
- if ( ! indeterminate(_validRepoSignature) ) return _validRepoSignature;
- // check metadata:
- if ( ! metadatapath.empty() )
- {
- //TODO: a missing ".repo_gpgcheck" might be plaindir(no Downloader) or not yet refreshed signed repo!
- TriBool linkval = triBoolFromPath( metadatapath / ".repo_gpgcheck" );
- return linkval;
- }
- return indeterminate;
- }
-
- void internalSetValidRepoSignature( TriBool value_r )
- {
- if ( PathInfo(metadatapath).isDir() )
- {
- Pathname gpgcheckFile( metadatapath / ".repo_gpgcheck" );
- if ( PathInfo(gpgcheckFile).isExist() )
- {
- TriBool linkval( indeterminate );
- if ( triBoolFromPath( gpgcheckFile, linkval ) && linkval == value_r )
- return; // existing symlink fits value_r
- else
- filesystem::unlink( gpgcheckFile ); // will write a new one
- }
- filesystem::symlink( asString(value_r), gpgcheckFile );
- }
- _validRepoSignature = value_r;
- }
-
- bool triBoolFromPath( const Pathname & path_r, TriBool & ret_r ) const
- {
- static const Pathname truePath( "true" );
- static const Pathname falsePath( "false" );
- static const Pathname indeterminatePath( "indeterminate" );
- Pathname linkval( filesystem::readlink( path_r ) );
- bool known = true;
- if ( linkval == truePath )
- ret_r = true;
- else if ( linkval == falsePath )
- ret_r = false;
- else if ( linkval == indeterminatePath )
- ret_r = indeterminate;
- else
- known = false;
- return known;
- }
-
- TriBool triBoolFromPath( const Pathname & path_r ) const
- { TriBool ret(indeterminate); triBoolFromPath( path_r, ret ); return ret; }
-
- //@}
-
- public:
- TriBool _gpgCheck; ///< default gpgcheck behavior: Y/N/ZConf
- TriBool _repoGpgCheck; ///< need to check repo sign.: Y/N/(ZConf(Y/N/gpgCheck))
- TriBool _pkgGpgCheck; ///< need to check pkg sign.: Y/N/(ZConf(Y/N/gpgCheck && no valid repo sign.))
- private:
- TriBool _validRepoSignature;///< have signed and valid repo metadata
public:
+ TriBool gpgcheck;
TriBool keeppackages;
+ RepoVariablesReplacedUrl _gpgKeyUrl;
RepoVariablesReplacedUrl _mirrorListUrl;
repo::RepoType type;
Pathname path;
mutable RepoVariablesReplacedUrlList _baseUrls;
mutable std::set<std::string> _keywords;
- RepoVariablesReplacedUrlList _gpgKeyUrls;
-
friend Impl * rwcowClone<Impl>( const Impl * rhs );
/** clone for RWCOW_pointer */
Impl * clone() const
const RepoInfo RepoInfo::noRepo;
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : RepoInfo::RepoInfo
+ // METHOD TYPE : Ctor
+ //
RepoInfo::RepoInfo()
: _pimpl( new Impl() )
{}
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : RepoInfo::~RepoInfo
+ // METHOD TYPE : Dtor
+ //
RepoInfo::~RepoInfo()
- {}
+ {
+ //MIL << std::endl;
+ }
unsigned RepoInfo::priority() const
{ return _pimpl->priority; }
void RepoInfo::setPriority( unsigned newval_r )
{ _pimpl->priority = newval_r ? newval_r : Impl::defaultPriority; }
-
- bool RepoInfo::gpgCheck() const
- { return indeterminate(_pimpl->_gpgCheck) ? ZConfig::instance().gpgCheck() : (bool)_pimpl->_gpgCheck; }
-
- void RepoInfo::setGpgCheck( TriBool value_r )
- { _pimpl->_gpgCheck = value_r; }
-
- void RepoInfo::setGpgCheck( bool value_r ) // deprecated legacy and for squid
- { setGpgCheck( TriBool(value_r) ); }
-
-
- bool RepoInfo::repoGpgCheck() const
- {
- if ( ! indeterminate(_pimpl->_repoGpgCheck) ) return _pimpl->_repoGpgCheck;
- if ( ! indeterminate(ZConfig::instance().repoGpgCheck()) ) return ZConfig::instance().repoGpgCheck();
- return gpgCheck(); // no preference: follow gpgCheck
- }
-
- void RepoInfo::setRepoGpgCheck( TriBool value_r )
- { _pimpl->_repoGpgCheck = value_r; }
-
-
- bool RepoInfo::pkgGpgCheck() const
- {
- if ( ! indeterminate(_pimpl->_pkgGpgCheck) ) return _pimpl->_pkgGpgCheck;
- if ( ! indeterminate(ZConfig::instance().pkgGpgCheck()) ) return ZConfig::instance().pkgGpgCheck();
- // no preference: follow gpgCheck and check package if repo signature not available or not checked
- return gpgCheck() && ( !repoGpgCheck() || !(bool)validRepoSignature() ); // !(bool)TriBool ==> false or indeterminate
- }
-
- void RepoInfo::setPkgGpgCheck( TriBool value_r )
- { _pimpl->_pkgGpgCheck = value_r; }
-
- void RepoInfo::getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const
- {
- g_r = _pimpl->_gpgCheck;
- r_r = _pimpl->_repoGpgCheck;
- p_r = _pimpl->_pkgGpgCheck;
- }
-
- TriBool RepoInfo::validRepoSignature() const
- {
- TriBool ret = _pimpl->internalValidRepoSignature();
- // keep indeterminate(=unsigned) but invalidate any signature if !repoGpgCheck
- if ( !indeterminate(ret) && !repoGpgCheck() )
- ret = false;
- return ret;
- }
-
- void RepoInfo::setValidRepoSignature( TriBool value_r )
- { _pimpl->internalSetValidRepoSignature( value_r ); }
-
+ void RepoInfo::setGpgCheck( bool check )
+ { _pimpl->gpgcheck = check; }
void RepoInfo::setMirrorListUrl( const Url & url_r ) // Raw
{ _pimpl->_mirrorListUrl.raw() = url_r; }
- void RepoInfo::setGpgKeyUrls( url_set urls )
- { _pimpl->gpgKeyUrls().raw().swap( urls ); }
-
void RepoInfo::setGpgKeyUrl( const Url & url_r )
- {
- _pimpl->gpgKeyUrls().raw().clear();
- _pimpl->gpgKeyUrls().raw().push_back( url_r );
- }
+ { _pimpl->_gpgKeyUrl.raw() = url_r; }
void RepoInfo::addBaseUrl( const Url & url_r )
{
_pimpl->baseUrls().raw().push_back( url_r );
}
- void RepoInfo::setBaseUrls( url_set urls )
- { _pimpl->baseUrls().raw().swap( urls ); }
-
void RepoInfo::setPath( const Pathname &path )
{ _pimpl->path = path; }
void RepoInfo::setTargetDistribution( const std::string & targetDistribution )
{ _pimpl->targetDistro = targetDistribution; }
+ bool RepoInfo::gpgCheck() const
+ { return indeterminate(_pimpl->gpgcheck) ? true : (bool)_pimpl->gpgcheck; }
+
bool RepoInfo::keepPackages() const
{ return indeterminate(_pimpl->keeppackages) ? false : (bool)_pimpl->keeppackages; }
Url RepoInfo::rawMirrorListUrl() const // Raw
{ return _pimpl->_mirrorListUrl.raw(); }
- bool RepoInfo::gpgKeyUrlsEmpty() const
- { return _pimpl->gpgKeyUrls().empty(); }
-
- RepoInfo::urls_size_type RepoInfo::gpgKeyUrlsSize() const
- { return _pimpl->gpgKeyUrls().size(); }
-
- RepoInfo::url_set RepoInfo::gpgKeyUrls() const // Variables replaced!
- { return _pimpl->gpgKeyUrls().transformed(); }
-
- RepoInfo::url_set RepoInfo::rawGpgKeyUrls() const // Raw
- { return _pimpl->gpgKeyUrls().raw(); }
-
Url RepoInfo::gpgKeyUrl() const // Variables replaced!
- { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().transformedBegin() ); }
+ { return _pimpl->_gpgKeyUrl.transformed(); }
Url RepoInfo::rawGpgKeyUrl() const // Raw
- { return( _pimpl->gpgKeyUrls().empty() ? Url() : *_pimpl->gpgKeyUrls().rawBegin() ) ; }
+ { return _pimpl->_gpgKeyUrl.raw(); }
RepoInfo::url_set RepoInfo::baseUrls() const // Variables replaced!
{ return _pimpl->baseUrls().transformed(); }
strif( "- path : ", path().asString() );
str << "- type : " << type() << std::endl;
str << "- priority : " << priority() << std::endl;
-
- // Yes No Default(Y) Default(N)
-#define OUTS(T,B) ( indeterminate(T) ? (std::string("D(")+(B?"Y":"N")+")") : ((bool)T?"Y":"N") )
- str << "- gpgcheck : " << OUTS(_pimpl->_gpgCheck,gpgCheck())
- << " repo" << OUTS(_pimpl->_repoGpgCheck,repoGpgCheck())
- << " sig" << asString( validRepoSignature(), "?", "Y", "N" )
- << " pkg" << OUTS(_pimpl->_pkgGpgCheck,pkgGpgCheck())
- << std::endl;
-#undef OUTS
-
- for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
- {
- str << "- gpgkey : " << url << std::endl;
- }
+ str << "- gpgcheck : " << gpgCheck() << std::endl;
+ strif( "- gpgkey : ", rawGpgKeyUrl().asString() );
if ( ! indeterminate(_pimpl->keeppackages) )
str << "- keeppackages: " << keepPackages() << std::endl;
if ( priority() != defaultPriority() )
str << "priority=" << priority() << endl;
- if ( ! indeterminate(_pimpl->_gpgCheck) )
- str << "gpgcheck=" << (_pimpl->_gpgCheck ? "1" : "0") << endl;
-
- if ( ! indeterminate(_pimpl->_repoGpgCheck) )
- str << "repo_gpgcheck=" << (_pimpl->_repoGpgCheck ? "1" : "0") << endl;
-
- if ( ! indeterminate(_pimpl->_pkgGpgCheck) )
- str << "pkg_gpgcheck=" << (_pimpl->_pkgGpgCheck ? "1" : "0") << endl;
+ if (!indeterminate(_pimpl->gpgcheck))
+ str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
- {
- std::string indent( "gpgkey=");
- for ( const auto & url : _pimpl->gpgKeyUrls().raw() )
- {
- str << indent << url << endl;
- if ( indent[0] != ' ' )
- indent = " ";
- }
- }
+ if ( ! (rawGpgKeyUrl().asString().empty()) )
+ str << "gpgkey=" << rawGpgKeyUrl() << endl;
if (!indeterminate(_pimpl->keeppackages))
str << "keeppackages=" << keepPackages() << endl;
<< " priority=\"" << priority() << "\""
<< " enabled=\"" << enabled() << "\""
<< " autorefresh=\"" << autorefresh() << "\""
- << " gpgcheck=\"" << gpgCheck() << "\""
- << " repo_gpgcheck=\"" << repoGpgCheck() << "\""
- << " pkg_gpgcheck=\"" << pkgGpgCheck() << "\"";
+ << " gpgcheck=\"" << gpgCheck() << "\"";
if (!(tmpstr = gpgKeyUrl().asString()).empty())
str << " gpgkey=\"" << escape(tmpstr) << "\"";
if (!(tmpstr = mirrorListUrl().asString()).empty())