}
#include <iostream>
#include <fstream>
-#include "zypp/base/Logger.h"
+#include "zypp/base/LogTools.h"
#include "zypp/base/IOStream.h"
#include "zypp/base/InputStream.h"
#include "zypp/base/String.h"
+#include "zypp/base/Regex.h"
#include "zypp/ZConfig.h"
#include "zypp/ZYppFactory.h"
#include "zypp/parser/IniDict.h"
#include "zypp/sat/Pool.h"
+#include "zypp/sat/detail/PoolImpl.h"
using namespace std;
using namespace zypp::filesystem;
*/
Locale _autodetectTextLocale()
{
- Locale ret( "en" );
+ Locale ret( Locale::enCode );
const char * envlist[] = { "LC_ALL", "LC_MESSAGES", "LANG", NULL };
for ( const char ** envvar = envlist; *envvar; ++envvar )
{
if ( envstr != "POSIX" && envstr != "C" )
{
Locale lang( envstr );
- if ( ! lang.code().empty() )
+ if ( lang )
{
MIL << "Found " << *envvar << "=" << envstr << endl;
ret = lang;
return ret;
}
+
+ inline Pathname _autodetectSystemRoot()
+ {
+ Target_Ptr target( getZYpp()->getTarget() );
+ return target ? target->root() : Pathname();
+ }
+
+ inline Pathname _autodetectZyppConfPath()
+ {
+ const char *env_confpath = getenv( "ZYPP_CONF" );
+ return env_confpath ? env_confpath : "/etc/zypp/zypp.conf";
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
/** Mutable option. */
- template<class _Tp>
+ template<class Tp>
struct Option
{
- typedef _Tp value_type;
+ typedef Tp value_type;
/** No default ctor, explicit initialisation! */
Option( const value_type & initial_r )
};
/** Mutable option with initial value also remembering a config value. */
- template<class _Tp>
- struct DefaultOption : public Option<_Tp>
+ template<class Tp>
+ struct DefaultOption : public Option<Tp>
{
- typedef _Tp value_type;
- typedef Option<_Tp> option_type;
+ typedef Tp value_type;
+ typedef Option<Tp> option_type;
DefaultOption( const value_type & initial_r )
- : Option<_Tp>( initial_r ), _default( initial_r )
+ : Option<Tp>( initial_r ), _default( initial_r )
{}
/** Reset value to the current default. */
*/
class ZConfig::Impl
{
+ typedef std::set<std::string> MultiversionSpec;
+
public:
Impl( const Pathname & override_r = Pathname() )
: _parsedZyppConf ( override_r )
, download_use_deltarpm ( true )
, download_use_deltarpm_always ( false )
, download_media_prefer_download( true )
+ , download_mediaMountdir ( "/var/adm/mount" )
, download_max_concurrent_connections( 5 )
, download_min_download_speed ( 0 )
, download_max_download_speed ( 0 )
, pkgGpgCheck ( indeterminate )
, solver_onlyRequires ( false )
, solver_allowVendorChange ( false )
+ , solver_dupAllowDowngrade ( true )
+ , solver_dupAllowNameChange ( true )
+ , solver_dupAllowArchChange ( true )
+ , solver_dupAllowVendorChange ( true )
, solver_cleandepsOnRemove ( false )
, solver_upgradeTestcasesToKeep ( 2 )
, solverUpgradeRemoveDroppedPackages( true )
, apply_locks_file ( true )
, pluginsPath ( "/usr/lib/zypp/plugins" )
{
- MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
+ MIL << "libzypp: " << VERSION << endl;
// override_r has higest prio
// ZYPP_CONF might override /etc/zypp/zypp.conf
if ( _parsedZyppConf.empty() )
{
- const char *env_confpath = getenv( "ZYPP_CONF" );
- _parsedZyppConf = env_confpath ? env_confpath : "/etc/zypp/zypp.conf";
+ _parsedZyppConf = _autodetectZyppConfPath();
}
else
{
{
download_media_prefer_download.restoreToDefault( str::compareCI( value, "volatile" ) != 0 );
}
+
+ else if ( entry == "download.media_mountdir" )
+ {
+ download_mediaMountdir.restoreToDefault( Pathname(value) );
+ }
+
else if ( entry == "download.max_concurrent_connections" )
{
str::strtonum(value, download_max_concurrent_connections);
}
else if ( entry == "gpgcheck" )
{
- gpgCheck.restoreToDefault( str::strToBool( value, gpgCheck ) );
+ gpgCheck.set( str::strToBool( value, gpgCheck ) );
}
else if ( entry == "repo_gpgcheck" )
{
- repoGpgCheck.restoreToDefault( str::strToTriBool( value ) );
+ repoGpgCheck.set( str::strToTriBool( value ) );
}
else if ( entry == "pkg_gpgcheck" )
{
- pkgGpgCheck.restoreToDefault( str::strToTriBool( value ) );
+ pkgGpgCheck.set( str::strToTriBool( value ) );
}
else if ( entry == "vendordir" )
{
{
solver_allowVendorChange.set( str::strToBool( value, solver_allowVendorChange ) );
}
+ else if ( entry == "solver.dupAllowDowngrade" )
+ {
+ solver_dupAllowDowngrade.set( str::strToBool( value, solver_dupAllowDowngrade ) );
+ }
+ else if ( entry == "solver.dupAllowNameChange" )
+ {
+ solver_dupAllowNameChange.set( str::strToBool( value, solver_dupAllowNameChange ) );
+ }
+ else if ( entry == "solver.dupAllowArchChange" )
+ {
+ solver_dupAllowArchChange.set( str::strToBool( value, solver_dupAllowArchChange ) );
+ }
+ else if ( entry == "solver.dupAllowVendorChange" )
+ {
+ solver_dupAllowVendorChange.set( str::strToBool( value, solver_dupAllowVendorChange ) );
+ }
else if ( entry == "solver.cleandepsOnRemove" )
{
solver_cleandepsOnRemove.set( str::strToBool( value, solver_cleandepsOnRemove ) );
{
solver_checkSystemFile = Pathname(value);
}
+ else if ( entry == "solver.checkSystemFileDir" )
+ {
+ solver_checkSystemFileDir = Pathname(value);
+ }
else if ( entry == "multiversion" )
{
- str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
+ MultiversionSpec & defSpec( _multiversionMap.getDefaultSpec() );
+ str::splitEscaped( value, std::inserter( defSpec, defSpec.end() ), ", \t" );
}
else if ( entry == "locksfile.path" )
{
}
}
}
+ //
+
}
else
{
bool download_use_deltarpm;
bool download_use_deltarpm_always;
DefaultOption<bool> download_media_prefer_download;
+ DefaultOption<Pathname> download_mediaMountdir;
int download_max_concurrent_connections;
int download_min_download_speed;
Option<DownloadMode> commit_downloadMode;
- DefaultOption<bool> gpgCheck;
- DefaultOption<TriBool> repoGpgCheck;
- DefaultOption<TriBool> pkgGpgCheck;
+ Option<bool> gpgCheck;
+ Option<TriBool> repoGpgCheck;
+ Option<TriBool> pkgGpgCheck;
Option<bool> solver_onlyRequires;
Option<bool> solver_allowVendorChange;
+ Option<bool> solver_dupAllowDowngrade;
+ Option<bool> solver_dupAllowNameChange;
+ Option<bool> solver_dupAllowArchChange;
+ Option<bool> solver_dupAllowVendorChange;
Option<bool> solver_cleandepsOnRemove;
Option<unsigned> solver_upgradeTestcasesToKeep;
DefaultOption<bool> solverUpgradeRemoveDroppedPackages;
Pathname solver_checkSystemFile;
+ Pathname solver_checkSystemFileDir;
- std::set<std::string> & multiversion() { return getMultiversion(); }
- const std::set<std::string> & multiversion() const { return getMultiversion(); }
+ MultiversionSpec & multiversion() { return getMultiversion(); }
+ const MultiversionSpec & multiversion() const { return getMultiversion(); }
bool apply_locks_file;
Option<Pathname> pluginsPath;
private:
- std::set<std::string> & getMultiversion() const
+ // HACK for bnc#906096: let pool re-evaluate multiversion spec
+ // if target root changes. ZConfig returns data sensitive to
+ // current target root.
+ // TODO Actually we'd need to scan the target systems zypp.conf and
+ // overlay all system specific values.
+ struct MultiversionMap
{
- if ( ! _multiversionInitialized )
+ typedef std::map<Pathname,MultiversionSpec> SpecMap;
+
+ MultiversionSpec & getSpec( Pathname root_r, const Impl & zConfImpl_r ) // from system at root
{
- Pathname multiversionDir( cfg_multiversion_path );
+ // _specMap[] - the plain zypp.conf value
+ // _specMap[/] - combine [] and multiversion.d scan
+ // _specMap[root] - scan root/zypp.conf and root/multiversion.d
+
+ if ( root_r.empty() )
+ root_r == "/";
+ bool cacheHit = _specMap.count( root_r );
+ MultiversionSpec & ret( _specMap[root_r] ); // creates new entry on the fly
+
+ if ( ! cacheHit )
+ {
+ if ( root_r == "/" )
+ ret.swap( _specMap[Pathname()] ); // original zypp.conf
+ else
+ scanConfAt( root_r, ret, zConfImpl_r ); // scan zypp.conf at root_r
+ scanDirAt( root_r, ret, zConfImpl_r ); // add multiversion.d at root_r
+ using zypp::operator<<;
+ MIL << "MultiversionSpec '" << root_r << "' = " << ret << endl;
+ }
+ return ret;
+ }
+
+ MultiversionSpec & getDefaultSpec() // Spec from zypp.conf parsing; called before any getSpec
+ { return _specMap[Pathname()]; }
+
+ private:
+ void scanConfAt( const Pathname root_r, MultiversionSpec & spec_r, const Impl & zConfImpl_r )
+ {
+ static const str::regex rx( "^multiversion *= *(.*)" );
+ str::smatch what;
+ iostr::simpleParseFile( InputStream( Pathname::assertprefix( root_r, _autodetectZyppConfPath() ) ),
+ [&]( int num_r, std::string line_r )->bool
+ {
+ if ( line_r[0] == 'm' && str::regex_match( line_r, what, rx ) )
+ {
+ str::splitEscaped( what[1], std::inserter( spec_r, spec_r.end() ), ", \t" );
+ return false; // stop after match
+ }
+ return true;
+ } );
+ }
+
+ void scanDirAt( const Pathname root_r, MultiversionSpec & spec_r, const Impl & zConfImpl_r )
+ {
+ // NOTE: Actually we'd need to scan and use the root_r! zypp.conf values.
+ Pathname multiversionDir( zConfImpl_r.cfg_multiversion_path );
if ( multiversionDir.empty() )
- multiversionDir = ( cfg_config_path.empty() ? Pathname("/etc/zypp") : cfg_config_path ) / "multiversion.d";
+ multiversionDir = ( zConfImpl_r.cfg_config_path.empty()
+ ? Pathname("/etc/zypp")
+ : zConfImpl_r.cfg_config_path ) / "multiversion.d";
- filesystem::dirForEach( multiversionDir,
- [this]( const Pathname & dir_r, const char *const & name_r )->bool
+ filesystem::dirForEach( Pathname::assertprefix( root_r, multiversionDir ),
+ [&spec_r]( const Pathname & dir_r, const char *const & name_r )->bool
{
MIL << "Parsing " << dir_r/name_r << endl;
iostr::simpleParseFile( InputStream( dir_r/name_r ),
- [this]( int num_r, std::string line_r )->bool
+ [&spec_r]( int num_r, std::string line_r )->bool
{
DBG << " found " << line_r << endl;
- _multiversion.insert( line_r );
+ spec_r.insert( std::move(line_r) );
return true;
} );
return true;
} );
- _multiversionInitialized = true;
}
- return _multiversion;
- }
- mutable std::set<std::string> _multiversion;
- mutable DefaultIntegral<bool,false> _multiversionInitialized;
+
+ private:
+ SpecMap _specMap;
+ };
+
+ MultiversionSpec & getMultiversion() const
+ { return _multiversionMap.getSpec( _autodetectSystemRoot(), *this ); }
+
+ mutable MultiversionMap _multiversionMap;
};
///////////////////////////////////////////////////////////////////
{}
Pathname ZConfig::systemRoot() const
- {
- Target_Ptr target( getZYpp()->getTarget() );
- return target ? target->root() : Pathname();
- }
+ { return _autodetectSystemRoot(); }
///////////////////////////////////////////////////////////////////
//
long ZConfig::download_transfer_timeout() const
{ return _pimpl->download_transfer_timeout; }
+ Pathname ZConfig::download_mediaMountdir() const { return _pimpl->download_mediaMountdir; }
+ void ZConfig::set_download_mediaMountdir( Pathname newval_r ) { _pimpl->download_mediaMountdir.set( std::move(newval_r) ); }
+ void ZConfig::set_default_download_mediaMountdir() { _pimpl->download_mediaMountdir.restoreToDefault(); }
+
DownloadMode ZConfig::commit_downloadMode() const
{ return _pimpl->commit_downloadMode; }
+ bool ZConfig::gpgCheck() const
+ { return _pimpl->gpgCheck; }
- bool ZConfig::gpgCheck() const { return _pimpl->gpgCheck; }
- TriBool ZConfig::repoGpgCheck() const { return _pimpl->repoGpgCheck; }
- TriBool ZConfig::pkgGpgCheck() const { return _pimpl->pkgGpgCheck; }
-
- void ZConfig::setGpgCheck( bool val_r ) { _pimpl->gpgCheck.set( val_r ); }
- void ZConfig::setRepoGpgCheck( TriBool val_r ) { _pimpl->repoGpgCheck.set( val_r ); }
- void ZConfig::setPkgGpgCheck( TriBool val_r ) { _pimpl->pkgGpgCheck.set( val_r ); }
-
- void ZConfig::resetGpgCheck() { _pimpl->gpgCheck.restoreToDefault(); }
- void ZConfig::resetRepoGpgCheck() { _pimpl->repoGpgCheck.restoreToDefault(); }
- void ZConfig::resetPkgGpgCheck() { _pimpl->pkgGpgCheck.restoreToDefault(); }
+ TriBool ZConfig::repoGpgCheck() const
+ { return _pimpl->repoGpgCheck; }
+ TriBool ZConfig::pkgGpgCheck() const
+ { return _pimpl->pkgGpgCheck; }
bool ZConfig::solver_onlyRequires() const
{ return _pimpl->solver_onlyRequires; }
bool ZConfig::solver_allowVendorChange() const
{ return _pimpl->solver_allowVendorChange; }
+ bool ZConfig::solver_dupAllowDowngrade() const { return _pimpl->solver_dupAllowDowngrade; }
+ bool ZConfig::solver_dupAllowNameChange() const { return _pimpl->solver_dupAllowNameChange; }
+ bool ZConfig::solver_dupAllowArchChange() const { return _pimpl->solver_dupAllowArchChange; }
+ bool ZConfig::solver_dupAllowVendorChange() const { return _pimpl->solver_dupAllowVendorChange; }
+
bool ZConfig::solver_cleandepsOnRemove() const
{ return _pimpl->solver_cleandepsOnRemove; }
{ return ( _pimpl->solver_checkSystemFile.empty()
? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); }
+ Pathname ZConfig::solver_checkSystemFileDir() const
+ { return ( _pimpl->solver_checkSystemFileDir.empty()
+ ? (configPath()/"systemCheck.d") : _pimpl->solver_checkSystemFileDir ); }
+
unsigned ZConfig::solver_upgradeTestcasesToKeep() const
{ return _pimpl->solver_upgradeTestcasesToKeep; }
void ZConfig::setSolverUpgradeRemoveDroppedPackages( bool val_r ) { _pimpl->solverUpgradeRemoveDroppedPackages.set( val_r ); }
void ZConfig::resetSolverUpgradeRemoveDroppedPackages() { _pimpl->solverUpgradeRemoveDroppedPackages.restoreToDefault(); }
+ namespace
+ {
+ inline void sigMultiversionSpecChanged()
+ {
+ sat::detail::PoolMember::myPool().multiversionSpecChanged();
+ }
+ }
+
const std::set<std::string> & ZConfig::multiversionSpec() const { return _pimpl->multiversion(); }
- void ZConfig::multiversionSpec( std::set<std::string> new_r ) { _pimpl->multiversion().swap( new_r ); }
- void ZConfig::clearMultiversionSpec() { _pimpl->multiversion().clear(); }
- void ZConfig::addMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().insert( name_r ); }
- void ZConfig::removeMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().erase( name_r ); }
+ void ZConfig::multiversionSpec( std::set<std::string> new_r ) { _pimpl->multiversion().swap( new_r ); sigMultiversionSpecChanged(); }
+ void ZConfig::clearMultiversionSpec() { _pimpl->multiversion().clear(); sigMultiversionSpecChanged(); }
+ void ZConfig::addMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().insert( name_r ); sigMultiversionSpecChanged(); }
+ void ZConfig::removeMultiversionSpec( const std::string & name_r ) { _pimpl->multiversion().erase( name_r ); sigMultiversionSpecChanged(); }
bool ZConfig::apply_locks_file() const
{ return _pimpl->apply_locks_file; }
std::ostream & ZConfig::about( std::ostream & str ) const
{
- str << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
+ str << "libzypp: " << VERSION << endl;
str << "libsolv: " << solv_version;
if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) )