/** \file zypp/ZConfig.cc
*
*/
+extern "C"
+{
+#include <sys/utsname.h>
+#include <unistd.h>
+}
#include <iostream>
+#include <fstream>
#include "zypp/base/Logger.h"
+#include "zypp/base/IOStream.h"
#include "zypp/base/InputStream.h"
#include "zypp/base/String.h"
{ /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+
+ /** Determine system architecture evaluating \c uname and \c /proc/cpuinfo.
+ */
+ Arch _autodetectSystemArchitecture()
+ {
+ struct ::utsname buf;
+ if ( ::uname( &buf ) < 0 )
+ {
+ ERR << "Can't determine system architecture" << endl;
+ return Arch_noarch;
+ }
+
+ Arch architecture( buf.machine );
+ MIL << "Uname architecture is '" << buf.machine << "'" << endl;
+
+ // some CPUs report i686 but dont implement cx8 and cmov
+ // check for both flags in /proc/cpuinfo and downgrade
+ // to i586 if either is missing (cf bug #18885)
+ if ( architecture == Arch_i686 )
+ {
+ std::ifstream cpuinfo( "/proc/cpuinfo" );
+ if ( cpuinfo )
+ {
+ for( iostr::EachLine in( cpuinfo ); in; in.next() )
+ {
+ if ( str::hasPrefix( *in, "flags" ) )
+ {
+ if ( in->find( "cx8" ) == std::string::npos
+ || in->find( "cmov" ) == std::string::npos )
+ {
+ architecture = Arch_i586;
+ WAR << "CPU lacks 'cx8' or 'cmov': architecture downgraded to '" << architecture << "'" << endl;
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ ERR << "Cant open " << PathInfo("/proc/cpuinfo") << endl;
+ }
+ }
+ return architecture;
+ }
+
+ /** The locale to be used for texts and messages.
+ *
+ * For the encoding to be used the preference is
+ *
+ * LC_ALL, LC_CTYPE, LANG
+ *
+ * For the language of the messages to be used, the preference is
+ *
+ * LANGUAGE, LC_ALL, LC_MESSAGES, LANG
+ *
+ * Note that LANGUAGE can contain more than one locale name, it can be
+ * a list of locale names like for example
+ *
+ * LANGUAGE=ja_JP.UTF-8:de_DE.UTF-8:fr_FR.UTF-8
+
+ * \todo Support dynamic fallbacklists defined by LANGUAGE
+ */
+ Locale _autodetectTextLocale()
+ {
+ Locale ret( "en" );
+ const char * envlist[] = { "LC_ALL", "LC_MESSAGES", "LANG", NULL };
+ for ( const char ** envvar = envlist; *envvar; ++envvar )
+ {
+ const char * envlang = getenv( *envvar );
+ if ( envlang )
+ {
+ std::string envstr( envlang );
+ if ( envstr != "POSIX" && envstr != "C" )
+ {
+ Locale lang( envstr );
+ if ( ! lang.code().empty() )
+ {
+ MIL << "Found " << *envvar << "=" << envstr << endl;
+ ret = lang;
+ break;
+ }
+ }
+ }
+ }
+ MIL << "Default text locale is '" << ret << "'" << endl;
+ return ret;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace zypp
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
//
// CLASS NAME : ZConfig::Impl
//
{
public:
Impl()
- : repo_add_probe ( false )
+ : cfg_arch ( defaultSystemArchitecture() )
+ , cfg_textLocale ( defaultTextLocale() )
+ , repo_add_probe ( false )
, repo_refresh_delay ( 10 )
, download_use_patchrpm ( true )
, download_use_deltarpm ( true )
{
- MIL << "ZConfig singleton created." << endl;
+ MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
// ZYPP_CONF might override /etc/zypp/zypp.conf
-
const char *env_confpath = getenv( "ZYPP_CONF" );
-
Pathname confpath( env_confpath ? env_confpath : "/etc/zypp/zypp.conf" );
- if ( PathInfo(confpath).isExist())
+ if ( PathInfo(confpath).isExist() )
{
- InputStream is(confpath);
- dict.read(is);
+ parser::IniDict dict( confpath );
+ //InputStream is(confpath);
+
+ for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
+ sit != dict.sectionsEnd();
+ ++sit )
+ {
+ string section(*sit);
+ //MIL << section << endl;
+ for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
+ it != dict.entriesEnd(*sit);
+ ++it )
+ {
+ string entry(it->first);
+ string value(it->second);
+ //DBG << (*it).first << "=" << (*it).second << endl;
+ if ( section == "main" )
+ {
+ if ( entry == "arch" )
+ {
+ Arch carch( value );
+ if ( carch != cfg_arch )
+ {
+ WAR << "Overriding system architecture (" << cfg_arch << "): " << carch << endl;
+ cfg_arch = carch;
+ }
+ }
+ else if ( entry == "metadatadir" )
+ {
+ cfg_metadata_path = Pathname(value);
+ }
+ else if ( entry == "reposdir" )
+ {
+ cfg_known_repos_path = Pathname(value);
+ }
+ else if ( entry == "cachedir" )
+ {
+ cfg_cache_path = Pathname(value);
+ }
+ else if ( entry == "repo.add.probe" )
+ {
+ repo_add_probe = str::strToBool( value, repo_add_probe );
+ }
+ else if ( entry == "repo.refresh.delay" )
+ {
+ str::strtonum(value, repo_refresh_delay);
+ }
+ else if ( entry == "download.use_patchrpm" )
+ {
+ download_use_patchrpm = str::strToBool( value, download_use_patchrpm );
+ }
+ else if ( entry == "download.use_deltarpm" )
+ {
+ download_use_deltarpm = str::strToBool( value, download_use_deltarpm );
+ }
+ else if ( entry == "vendordir" )
+ {
+ cfg_vendor_path = Pathname(value);
+ }
+ }
+ }
+ }
}
else
{
MIL << confpath << " not found, using defaults instead." << endl;
- return;
}
- for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
- sit != dict.sectionsEnd();
- ++sit )
+ // legacy:
+ if ( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) )
{
- string section(*sit);
- //MIL << section << endl;
- for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
- it != dict.entriesEnd(*sit);
- ++it )
+ Arch carch( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) );
+ if ( carch != cfg_arch )
{
- string entry(it->first);
- string value(it->second);
- //DBG << (*it).first << "=" << (*it).second << endl;
- if ( section == "main" )
- {
- if ( entry == "arch" )
- {
- cfg_arch = Arch(value);
- }
- else if ( entry == "metadatadir" )
- {
- cfg_metadata_path = Pathname(value);
- }
- else if ( entry == "reposdir" )
- {
- cfg_known_repos_path = Pathname(value);
- }
- else if ( entry == "cachedir" )
- {
- cfg_cache_path = Pathname(value);
- }
- else if ( entry == "repo.add.probe" )
- {
- repo_add_probe = str::strToBool( value, repo_add_probe );
- }
- else if ( entry == "repo.refresh.delay" )
- {
- str::strtonum(value, repo_refresh_delay);
- }
- else if ( entry == "download.use_patchrpm" )
- {
- download_use_patchrpm = str::strToBool( value, download_use_patchrpm );
- }
- else if ( entry == "download.use_deltarpm" )
- {
- download_use_deltarpm = str::strToBool( value, download_use_deltarpm );
- }
- else if ( entry == "vendordir" )
- {
- cfg_vendor_path = Pathname(value);
- }
- }
+ WAR << "ZYPP_TESTSUITE_FAKE_ARCH: Overriding system architecture (" << cfg_arch << "): " << carch << endl;
+ cfg_arch = carch;
}
}
+
+ MIL << "ZConfig singleton created." << endl;
+ MIL << "defaultTextLocale: '" << cfg_textLocale << "'" << endl;
+ MIL << "System architecture is '" << cfg_arch << "'" << endl;
}
~Impl()
{}
public:
- parser::IniDict dict;
-
- Arch cfg_arch;
+ Arch cfg_arch;
+ Locale cfg_textLocale;
Pathname cfg_metadata_path;
Pathname cfg_cache_path;
Pathname cfg_known_repos_path;
- Pathname cfg_vendor_path;
+ Pathname cfg_vendor_path;
bool repo_add_probe;
unsigned repo_refresh_delay;
//
ZConfig::ZConfig()
: _pimpl( new Impl )
- {
-
- }
+ {}
///////////////////////////////////////////////////////////////////
//
{}
///////////////////////////////////////////////////////////////////
-#warning change methods to use the singleton
-
- ///////////////////////////////////////////////////////////////////
//
- // METHOD NAME : ZConfig::systemArchitecture
- // METHOD TYPE : Arch
+ // system architecture
//
+ ///////////////////////////////////////////////////////////////////
+
+ Arch ZConfig::defaultSystemArchitecture()
+ {
+ static Arch _val( _autodetectSystemArchitecture() );
+ return _val;
+ }
+
Arch ZConfig::systemArchitecture() const
+ { return _pimpl->cfg_arch; }
+
+ void ZConfig::setSystemArchitecture( const Arch & arch_r )
{
- // get architecture from ZYpp() if not overriden,
- // ZYpp() knows how to retrieve the client arch and check cpu flags
- return ( (_pimpl->cfg_arch == Arch()) ?
- getZYpp()->architecture() : _pimpl->cfg_arch );
+ if ( arch_r != _pimpl->cfg_arch )
+ {
+ WAR << "Overriding system architecture (" << _pimpl->cfg_arch << "): " << arch_r << endl;
+ _pimpl->cfg_arch = arch_r;
+ }
}
///////////////////////////////////////////////////////////////////
//
- // METHOD NAME : ZConfig::overrideSystemArchitecture
- // METHOD TYPE : void
+ // text locale
//
- void ZConfig::overrideSystemArchitecture(const Arch & arch)
+ ///////////////////////////////////////////////////////////////////
+
+ Locale ZConfig::defaultTextLocale()
{
- WAR << "Overriding system architecture with " << arch << endl;
- _pimpl->cfg_arch = arch;
- getZYpp()->setArchitecture( arch );
+ static Locale _val( _autodetectTextLocale() );
+ return _val;
}
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : ZConfig::defaultTextLocale
- // METHOD TYPE : Locale
- //
Locale ZConfig::textLocale() const
+ { return _pimpl->cfg_textLocale; }
+
+ void ZConfig::setTextLocale( const Locale & locale_r )
{
- return getZYpp()->getTextLocale();
+ if ( locale_r != _pimpl->cfg_textLocale )
+ {
+ WAR << "Overriding text locale (" << _pimpl->cfg_textLocale << "): " << locale_r << endl;
+ _pimpl->cfg_textLocale = locale_r;
+ }
}
+ ///////////////////////////////////////////////////////////////////
+
Pathname ZConfig::repoMetadataPath() const
{
return ( _pimpl->cfg_metadata_path.empty()
Pathname ZConfig::vendorPath() const
{
return ( _pimpl->cfg_vendor_path.empty()
- ? Pathname("/etc/zypp/vendors.d") : _pimpl->cfg_vendor_path );
+ ? Pathname("/etc/zypp/vendors.d") : _pimpl->cfg_vendor_path );
}
/////////////////////////////////////////////////////////////////
#include <iosfwd>
+#include "zypp/base/Deprecated.h"
+
#include "zypp/base/NonCopyable.h"
#include "zypp/base/PtrTypes.h"
static ZConfig & instance();
public:
- /** The zypp system architecture. */
+
+ /** The autodetected system architecture. */
+ static Arch defaultSystemArchitecture();
+
+ /** The system architecture zypp uses. */
Arch systemArchitecture() const;
- /** Override the zypp system architecture, useful for test scenarious.
- This should be used for testing/debugging only since the Target backend
- won't be able to install incompatible packages !!
- DONT use for normal application unless you know what you're doing. */
- void overrideSystemArchitecture( const Arch & );
+ /** Override the zypp system architecture.
+ * This is useful for test scenarious. <b>But be warned</b>, zypp does
+ * not expect the system architecture to change at runtime. So
+ * set it at the verry beginning before you acess any other
+ * zypp component.
+ */
+ void setSystemArchitecture( const Arch & arch_r );
- /** The prefered locale for translated labels, descriptions,
- * descriptions, etc. passed to the UI.
+ /** Reset the zypp system architecture to the default. */
+ void resetSystemArchitecture()
+ { setSystemArchitecture( defaultSystemArchitecture() ); }
+
+ /** use setSystemArchitecture */
+ ZYPP_DEPRECATED void overrideSystemArchitecture( const Arch & arch_r )
+ { setSystemArchitecture( arch_r ); }
+
+ public:
+ /** The autodetected prefered locale for translated texts.
+ */
+ static Locale defaultTextLocale();
+
+ /** The locale for translated texts zypp uses.
*/
Locale textLocale() const;
- /**
+ /** Set the prefered locale for translated texts. */
+ void setTextLocale( const Locale & locale_r );
+
+ /** Reset the locale for translated texts to the default. */
+ void resetTextLocale()
+ { setTextLocale( defaultTextLocale() ); }
+
+ public:
+ /**
* Path where the repo metadata is downloaded and kept.
*/
Pathname repoMetadataPath() const;
#include "zypp/base/ReferenceCounted.h"
#include "zypp/base/NonCopyable.h"
#include "zypp/base/PtrTypes.h"
-
#include "zypp/base/Deprecated.h"
+
+#include "zypp/ZConfig.h"
+
#include "zypp/ZYppCommit.h"
#include "zypp/ResTraits.h"
public:
/** Set the preferred locale for translated labels, descriptions,
* etc. passed to the UI.
+ * \deprecated Use ZConfig diretcly.
*/
- void setTextLocale( const Locale & textLocale_r );
- /** */
- Locale getTextLocale() const;
+ ZYPP_DEPRECATED void setTextLocale( const Locale & textLocale_r )
+ { ZConfig::instance().setTextLocale( textLocale_r ); }
+ /** \deprecated Use ZConfig diretcly. */
+ ZYPP_DEPRECATED Locale getTextLocale() const
+ { return ZConfig::instance().textLocale(); }
public:
+ /** \name move to pool
+ */
+ //@{
typedef std::set<Locale> LocaleSet;
/** Set the requested locales.
* Languages to be supported by the system, e.g. language specific
* internal use only
**/
void availableLocale( const Locale & locale_r );
+ //@}
public:
/** Get the path where zypp related plugins store persistent data and caches */
/** set the home, if you need to change it */
void setHomePath( const Pathname & path );
- /** Get the system architecture. */
- Arch architecture() const;
+ /** Get the system architecture.
+ * \deprecated Use ZConfig diretcly.
+ */
+ ZYPP_DEPRECATED Arch architecture() const
+ { return ZConfig::instance().systemArchitecture(); }
/** Set the system architecture.
- This should be used for testing/debugging only since the Target backend
- won't be able to install incompatible packages ;-) */
- void setArchitecture( const Arch & arch );
+ * This should be used for testing/debugging only since the Target backend
+ * won't be able to install incompatible packages ;-)
+ * \deprecated Use ZConfig diretcly.
+ */
+ ZYPP_DEPRECATED void setArchitecture( const Arch & arch )
+ { ZConfig::instance().setSystemArchitecture( arch ); }
public:
*
*/
-#include <sys/utsname.h>
-#include <unistd.h>
#include <iostream>
-#include <fstream>
#include "zypp/TmpPath.h"
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
namespace zypp_detail
{ /////////////////////////////////////////////////////////////////
- /** The locale to be used for texts and messages.
- *
- * For the encoding to be used the preference is
- *
- * LC_ALL, LC_CTYPE, LANG
- *
- * For the language of the messages to be used, the preference is
- *
- * LANGUAGE, LC_ALL, LC_MESSAGES, LANG
- *
- * Note that LANGUAGE can contain more than one locale name, it can be
- * a list of locale names like for example
- *
- * LANGUAGE=ja_JP.UTF-8:de_DE.UTF-8:fr_FR.UTF-8
-
- * \todo Support dynamic fallbacklists defined by LANGUAGE
- */
- inline Locale defaultTextLocale()
- {
- Locale ret( "en" );
- const char * envlist[] = { "LC_ALL", "LC_MESSAGES", "LANG", NULL };
- for ( const char ** envvar = envlist; *envvar; ++envvar )
- {
- const char * envlang = getenv( *envvar );
- if ( envlang )
- {
- std::string envstr( envlang );
- if ( envstr != "POSIX" && envstr != "C" )
- {
- Locale lang( envlang );
- if ( ! lang.code().empty() )
- {
- ret = lang;
- break;
- }
- }
- }
- }
- return ret;
- }
-
- Arch defaultArchitecture()
- {
- Arch architecture;
-
- // detect the true architecture
- struct utsname buf;
- if ( uname( &buf ) < 0 )
- {
- ERR << "Can't determine system architecture" << endl;
- }
- else
- {
- architecture = Arch( buf.machine );
- DBG << "uname architecture is '" << buf.machine << "'" << endl;
-
- // some CPUs report i686 but dont implement cx8 and cmov
- // check for both flags in /proc/cpuinfo and downgrade
- // to i586 if either is missing (cf bug #18885)
-
- if ( architecture == Arch_i686 )
- {
- std::ifstream cpuinfo( "/proc/cpuinfo" );
- if ( !cpuinfo )
- {
- ERR << "Cant open /proc/cpuinfo" << endl;
- }
- else
- {
- char infoline[1024];
- while ( cpuinfo.good() )
- {
- if ( !cpuinfo.getline( infoline, 1024, '\n' ) )
- {
- if ( cpuinfo.eof() )
- break;
- }
- if ( strncmp( infoline, "flags", 5 ) == 0 )
- {
- std::string flagsline( infoline );
- if ( flagsline.find( "cx8" ) == std::string::npos
- || flagsline.find( "cmov" ) == std::string::npos )
- {
- architecture = Arch_i586;
- DBG << "CPU lacks 'cx8' or 'cmov': architecture downgraded to '" << architecture << "'" << endl;
- }
- break;
- } // flags found
- } // read proc/cpuinfo
- } // proc/cpuinfo opened
- } // i686 extra flags check
- }
-
- if ( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) )
- {
- architecture = Arch( getenv( "ZYPP_TESTSUITE_FAKE_ARCH" ) );
- WAR << "ZYPP_TESTSUITE_FAKE_ARCH: Setting fake system architecture for test purpuses to: '" << architecture << "'" << endl;
- }
-
- return architecture;
- }
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : ZYppImpl::ZYppImpl
// METHOD TYPE : Constructor
//
ZYppImpl::ZYppImpl()
- : _textLocale( defaultTextLocale() )
- , _target(0)
+ : _target(0)
, _resolver( new Resolver( ResPool::instance()) )
- , _architecture( defaultArchitecture() )
{
- MIL << "libzypp: " << VERSION << " built " << __DATE__ << " " << __TIME__ << endl;
- MIL << "defaultTextLocale: '" << _textLocale << "'" << endl;
- MIL << "System architecture is '" << _architecture << "'" << endl;
-
- MIL << "initializing keyring..." << std::endl;
+ MIL << "Initializing keyring..." << std::endl;
//_keyring = new KeyRing(homePath() + Pathname("/keyring/all"), homePath() + Pathname("/keyring/trusted"));
_keyring = new KeyRing(tmpPath());
}
}
//------------------------------------------------------------------------
- // architecture
-
- void ZYppImpl::setArchitecture( const Arch & arch )
- {
- _architecture = arch;
- }
-
- //------------------------------------------------------------------------
// target store path
Pathname ZYppImpl::homePath() const