From: DongHun Kwak Date: Fri, 27 Nov 2020 06:45:45 +0000 (+0900) Subject: Imported Upstream version 17.20.0 X-Git-Tag: upstream/17.20.0^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Flibzypp.git;a=commitdiff_plain;h=1f206940fbbd2652d4715716c16385f081df544c Imported Upstream version 17.20.0 --- diff --git a/.gitignore b/.gitignore index 9550074..b445b4e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ build .settings *flymake.h.gch CMakeLists.txt.user* +zypp/APIConfig.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f0ca27..29c17b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,12 +43,14 @@ endif(COMMAND cmake_policy) INCLUDE(ZyppCommon) INCLUDE( ${LIBZYPP_SOURCE_DIR}/VERSION.cmake ) +MATH( EXPR LIBZYPP_NUMVERSION "${LIBZYPP_MAJOR} * 10000 + ${LIBZYPP_MINOR} * 100 + ${LIBZYPP_PATCH}" ) MATH( EXPR LIBZYPP_CURRENT "${LIBZYPP_MAJOR} * 100 + ${LIBZYPP_MINOR}" ) MATH( EXPR LIBZYPP_AGE "${LIBZYPP_MINOR} - ${LIBZYPP_COMPATMINOR}" ) # Libtool wanted current:patch:age # But cmake is not libtool, it wants the verbatim suffix to libzypp.so MATH( EXPR LIBZYPP_SO_FIRST "${LIBZYPP_CURRENT}-${LIBZYPP_AGE}" ) SET( VERSION "${LIBZYPP_MAJOR}.${LIBZYPP_MINOR}.${LIBZYPP_PATCH}" ) +CONFIGURE_FILE ( zypp/APIConfig.h.in zypp/APIConfig.h ) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) @@ -84,7 +86,6 @@ IF(${PIPE2_FOUND}) ENDIF(${PIPE2_FOUND}) ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 ) -ADD_DEFINITIONS( -DVERSION="${VERSION}" ) SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" ) SET( LIBZYPP_SOVERSION_INFO "${LIBZYPP_SO_FIRST}" ) diff --git a/VERSION.cmake b/VERSION.cmake index c83385e..794a6aa 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -59,10 +59,10 @@ # See './mkChangelog -h' for help. # SET(LIBZYPP_MAJOR "17") -SET(LIBZYPP_COMPATMINOR "12") -SET(LIBZYPP_MINOR "19") +SET(LIBZYPP_COMPATMINOR "20") +SET(LIBZYPP_MINOR "20") SET(LIBZYPP_PATCH "0") # -# LAST RELEASED: 17.19.0 (12) +# LAST RELEASED: 17.20.0 (20) # (The number in parenthesis is LIBZYPP_COMPATMINOR) #======= diff --git a/libzypp.spec.cmake b/libzypp.spec.cmake index 376b6a1..3b81e75 100644 --- a/libzypp.spec.cmake +++ b/libzypp.spec.cmake @@ -71,7 +71,7 @@ BuildRequires: pkgconfig BuildRequires: pkg-config %endif -BuildRequires: libsolv-devel >= 0.7.8 +BuildRequires: libsolv-devel >= 0.7.10 %if 0%{?suse_version} >= 1100 BuildRequires: libsolv-tools %requires_eq libsolv-tools diff --git a/package/libzypp.changes b/package/libzypp.changes index f5eeaca..ae85e51 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,16 @@ ------------------------------------------------------------------- +Thu Dec 19 13:28:00 CET 2019 - ma@suse.de + +- BuildRequires: libsolv-devel >= 0.7.10. +- RpmDb: Become rpmdb backend independent (jsc#SLE-7272) +- RpmDb: Close API offering a custom rpmdb path + It's actually not needed and for this to work also libsolv needs + to support it. You can sill use a librpmDb::db_const_iterator to + access a database at a custom location (ro). +- Remove legacy rpmV3database conversion code. +- version 17.20.0 (20) + +------------------------------------------------------------------- Wed Dec 11 09:51:10 CET 2019 - ma@suse.de - MediaCurl: assert cookie file has mode 0600 (bsc#1158763, CVE-2019-18900) diff --git a/zypp/APIConfig.h b/zypp/APIConfig.h.in similarity index 80% rename from zypp/APIConfig.h rename to zypp/APIConfig.h.in index 4533c2b..1e540ea 100644 --- a/zypp/APIConfig.h +++ b/zypp/APIConfig.h.in @@ -14,6 +14,24 @@ #include "zypp/base/Easy.h" // some macros used almost everywhere +#define LIBZYPP_VERSION_STRING "@VERSION@" +#define LIBZYPP_VERSION_MAJOR @LIBZYPP_MAJOR@ +#define LIBZYPP_VERSION_MINOR @LIBZYPP_MINOR@ +#define LIBZYPP_VERSION_PATCH @LIBZYPP_PATCH@ +#define LIBZYPP_SOVERSION @LIBZYPP_SO_FIRST@ +#define LIBZYPP_VERSION @LIBZYPP_NUMVERSION@ + +/** + * Legacy code we still support. + * + * Deprecated items we can't drop immediately because YAST/PK still + * refer to them or they break binary compatibility, should be + * enclosed in `#if LEGACY(#)` where # is either a minor number(<=99), + * a soversion [<=9999] or numversion [<=999999]. + * + */ +#define LEGACY(CL) ( CL < 100 && LIBZYPP_VERSION_MAJOR <= CL ) || ( CL < 10000 && LIBZYPP_SOVERSION <= CL ) || LIBZYPP_VERSION <= CL + /** * Generic helper definitions for shared library support. * @@ -33,7 +51,7 @@ #if __GNUC__ >= 4 #define ZYPP_DECL_EXPORT __attribute__ ((visibility ("default"))) #define ZYPP_DECL_IMPORT __attribute__ ((visibility ("default"))) - #define ZYPP_DECL_HIDDEN __attribute__ ((visibility ("hidden"))) + #define ZYPP_DECL_HIDDEN __attribute__ ((visibility ("hidden"))) #else #define ZYPP_DECL_EXPORT #define ZYPP_DECL_IMPORT diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index 2523d5a..82bf074 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -95,7 +95,7 @@ SET( zypp_EARLY_SRCS ) SET( zypp_HEADERS - APIConfig.h + ${CMAKE_CURRENT_BINARY_DIR}/APIConfig.h Application.h Arch.h AutoDispose.h @@ -638,7 +638,6 @@ SET( zypp_target_rpm_SRCS target/rpm/RpmException.cc target/rpm/RpmHeader.cc target/rpm/librpmDb.cc - target/rpm/librpmDb.cv3.cc ) SET( zypp_target_rpm_HEADERS diff --git a/zypp/ProgressData.h b/zypp/ProgressData.h index 1cb757a..544349d 100644 --- a/zypp/ProgressData.h +++ b/zypp/ProgressData.h @@ -43,10 +43,10 @@ namespace zypp * it a name. * * \code - * bool exampleReceiver( ProgressData::value_type v ) + * bool exampleReceiver( const ProgressData & ticks_r ) * { - * DBG << "got ->" << v << endl; - * return( v <= 100 ); // Abort if ( v > 100 ) + * DBG << "got ->" << ticks_r.reportValue() << " (" << ticks_r.val() << ")" << endl; + * return( ticks_r.val() <= 100 ); // Abort if ( val > 100 ) * } * * class Example @@ -107,21 +107,21 @@ namespace zypp * \endcode * \code * Reporting %: - * got ->0 - * got ->10 - * got ->20 - * got ->30 - * got ->40 - * got ->50 - * got ->60 - * got ->70 - * got ->80 - * got ->90 - * got ->100 - * got ->100 + * got ->0 (0) + * got ->10 (1) + * got ->20 (2) + * got ->30 (3) + * got ->40 (4) + * got ->50 (5) + * got ->60 (6) + * got ->70 (7) + * got ->80 (8) + * got ->90 (9) + * got ->100 (10) + * got ->100 (10) * Reporting 'still alive': - * got ->0 - * got ->9 + * got ->-1 (0) + * got ->-1 (9) * \endcode * * The different ammount of triggers is due to different rules for sending diff --git a/zypp/RepoStatus.cc b/zypp/RepoStatus.cc index 42d2525..7a2ca5f 100644 --- a/zypp/RepoStatus.cc +++ b/zypp/RepoStatus.cc @@ -34,6 +34,21 @@ namespace zypp string _checksum; Date _timestamp; + // NOTE: Changing magic will at once invalidate all solv file caches. + // Helpfull if solv file content must be refreshed (e.g. due to different + // repo2* arguments) even if raw metadata are unchanged. + // Only values set from a RepoStatus ctor need magic to be added. + void assignFromCtor( std::string && checksum_r, Date && timestamp_r ) + { + _checksum = std::move(checksum_r); + _timestamp = std::move(timestamp_r); + if ( !_checksum.empty() ) + { + static const std::string magic( "43" ); + _checksum += magic; + } + } + /** Recursive computation of max dir timestamp. */ static void recursive_timestamp( const Pathname & dir_r, time_t & max_r ) { @@ -83,25 +98,23 @@ namespace zypp { if ( info.isFile() ) { - _pimpl->_timestamp = Date( info.mtime() ); - _pimpl->_checksum = filesystem::sha1sum( path_r ); + _pimpl->assignFromCtor( filesystem::sha1sum( path_r ), Date( info.mtime() ) ); } else if ( info.isDir() ) { time_t t = info.mtime(); Impl::recursive_timestamp( path_r, t ); - _pimpl->_timestamp = Date(t); - _pimpl->_checksum = CheckSum::sha1FromString( str::numstring( t ) ).checksum(); + _pimpl->assignFromCtor( CheckSum::sha1FromString( str::numstring( t ) ).checksum(), Date( t ) ); } - - // NOTE: changing magic will once invalidate all solv file caches - // Helpfull if solv file content must be refreshed (e.g. due to different - // repo2* arguments) even if raw metadata are unchanged. - static const std::string magic( "43" ); - _pimpl->_checksum += magic; } } + RepoStatus::RepoStatus( std::string checksum_r, Date timestamp_r ) + : _pimpl( new Impl() ) + { + _pimpl->assignFromCtor( std::move(checksum_r), std::move(timestamp_r) ); + } + RepoStatus::~RepoStatus() {} diff --git a/zypp/RepoStatus.h b/zypp/RepoStatus.h index 1eaa2da..184a365 100644 --- a/zypp/RepoStatus.h +++ b/zypp/RepoStatus.h @@ -52,6 +52,9 @@ namespace zypp */ explicit RepoStatus( const Pathname & path_r ); + /** Explicitly specify checksum string and timestamp to use. */ + RepoStatus( std::string checksum_r, Date timestamp_r ); + /** Dtor */ ~RepoStatus(); diff --git a/zypp/Target.cc b/zypp/Target.cc index b9d35ec..268237d 100644 --- a/zypp/Target.cc +++ b/zypp/Target.cc @@ -88,9 +88,6 @@ namespace zypp std::ostream & Target::dumpOn( std::ostream & str ) const { return _pimpl->dumpOn( str ); } - Date Target::timestamp() const - { return _pimpl->timestamp(); } - Product::constPtr Target::baseProduct() const { return _pimpl->baseProduct(); } diff --git a/zypp/Target.h b/zypp/Target.h index 1730c5c..5bed42c 100644 --- a/zypp/Target.h +++ b/zypp/Target.h @@ -101,9 +101,6 @@ namespace zypp Pathname assertRootPrefix( const Pathname & path_r ) const { return Pathname::assertprefix( root(), path_r ); } - /** return the last modification date of the target */ - Date timestamp() const; - /** * returns the target base installed product, also known as * the distribution or platform. diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc index ed80fa2..ba5c6fd 100644 --- a/zypp/ZConfig.cc +++ b/zypp/ZConfig.cc @@ -339,7 +339,7 @@ namespace zypp , apply_locks_file ( true ) , pluginsPath ( "/usr/lib/zypp/plugins" ) { - MIL << "libzypp: " << VERSION << endl; + MIL << "libzypp: " LIBZYPP_VERSION_STRING << endl; // override_r has higest prio // ZYPP_CONF might override /etc/zypp/zypp.conf if ( _parsedZyppConf.empty() ) @@ -1196,7 +1196,7 @@ namespace zypp std::ostream & ZConfig::about( std::ostream & str ) const { - str << "libzypp: " << VERSION << endl; + str << "libzypp: " LIBZYPP_VERSION_STRING << endl; str << "libsolv: " << solv_version; if ( ::strcmp( solv_version, LIBSOLV_VERSION_STRING ) ) diff --git a/zypp/ZYppCallbacks.h b/zypp/ZYppCallbacks.h index 667e8a4..b475539 100644 --- a/zypp/ZYppCallbacks.h +++ b/zypp/ZYppCallbacks.h @@ -626,40 +626,35 @@ namespace zypp ) {} }; +#if LEGACY(17) // progress for converting the database - struct ConvertDBReport : public callback::ReportBase + /// \deprecated Still used by y2-bindings in Code15 (libyzpp major 17) + struct ZYPP_DEPRECATED ConvertDBReport : public callback::ReportBase { enum Action { ABORT, // abort and return error - RETRY, // retry - IGNORE // ignore the failure + RETRY, // retry + IGNORE // ignore the failure }; enum Error { NO_ERROR, - FAILED // conversion failed + FAILED // conversion failed }; - virtual void start( - Pathname /*path*/ - ) {} + virtual void start( Pathname /*path*/ ) + {} - virtual bool progress(int /*value*/, Pathname /*path*/) + virtual bool progress( int/*value*/, Pathname/*path*/ ) { return true; } - virtual Action problem( - Pathname /*path*/ - , Error /*error*/ - , const std::string &/*description*/ - ) { return ABORT; } + virtual Action problem( Pathname/*path*/, Error/*error*/, const std::string &/*description*/ ) + { return ABORT; } - virtual void finish( - Pathname /*path*/ - , Error /*error*/ - , const std::string &/*reason*/ - ) {} + virtual void finish( Pathname/*path*/, Error/*error*/, const std::string &/*reason*/ ) + {} }; - +#endif ///////////////////////////////////////////////////////////////// } // namespace rpm /////////////////////////////////////////////////////////////////// diff --git a/zypp/media/MediaAccess.cc b/zypp/media/MediaAccess.cc index f56f260..265684e 100644 --- a/zypp/media/MediaAccess.cc +++ b/zypp/media/MediaAccess.cc @@ -171,13 +171,12 @@ MediaAccess::open (const Url& o_url, const Pathname & preferred_attach_point) else curl = new MediaCurl (url,preferred_attach_point); - UrlResolverPlugin::HeaderList::const_iterator it; - for (it = custom_headers.begin(); - it != custom_headers.end(); - ++it) { - std::string header = it->first + ": " + it->second; + for ( const auto & el : custom_headers ) { + std::string header { el.first }; + header += ": "; + header += el.second; MIL << "Added custom header -> " << header << endl; - curl->settings().addHeader(header); + curl->settings().addHeader( std::move(header) ); } _handler = curl; } diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc index c244896..9cd8e03 100644 --- a/zypp/media/MediaCurl.cc +++ b/zypp/media/MediaCurl.cc @@ -305,135 +305,146 @@ namespace zypp { */ void fillSettingsFromUrl( const Url &url, TransferSettings &s ) { - std::string param(url.getQueryParam("timeout")); - if( !param.empty()) + { + const std::string & param { url.getQueryParam("timeout") }; + if( ! param.empty() ) { long num = str::strtonum(param); - if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX) - s.setTimeout(num); + if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX ) + s.setTimeout( num ); } - - if ( ! url.getUsername().empty() ) + } + { + std::string param { url.getUsername() }; + if ( ! param.empty() ) { - s.setUsername(url.getUsername()); - if ( url.getPassword().size() ) - s.setPassword(url.getPassword()); + s.setUsername( std::move(param) ); + param = url.getPassword(); + if ( ! param.empty() ) + s.setPassword( std::move(param) ); } else { - // if there is no username, set anonymous auth - if ( ( url.getScheme() == "ftp" || url.getScheme() == "tftp" ) && s.username().empty() ) - s.setAnonymousAuth(); + // if there is no username, set anonymous auth + if ( ( url.getScheme() == "ftp" || url.getScheme() == "tftp" ) && s.username().empty() ) + s.setAnonymousAuth(); } + } + if ( url.getScheme() == "https" ) + { + s.setVerifyPeerEnabled( false ); + s.setVerifyHostEnabled( false ); - if ( url.getScheme() == "https" ) + const std::string & verify { url.getQueryParam("ssl_verify") }; + if( verify.empty() || verify == "yes" ) { - s.setVerifyPeerEnabled(false); - s.setVerifyHostEnabled(false); - - std::string verify( url.getQueryParam("ssl_verify")); - if( verify.empty() || - verify == "yes") - { - s.setVerifyPeerEnabled(true); - s.setVerifyHostEnabled(true); - } - else if( verify == "no") - { - s.setVerifyPeerEnabled(false); - s.setVerifyHostEnabled(false); - } - else - { - std::vector flags; - std::vector::const_iterator flag; - str::split( verify, std::back_inserter(flags), ","); - for(flag = flags.begin(); flag != flags.end(); ++flag) - { - if( *flag == "host") - s.setVerifyHostEnabled(true); - else if( *flag == "peer") - s.setVerifyPeerEnabled(true); - else - ZYPP_THROW(MediaBadUrlException(url, "Unknown ssl_verify flag")); - } - } + s.setVerifyPeerEnabled( true ); + s.setVerifyHostEnabled( true ); } - - Pathname ca_path( url.getQueryParam("ssl_capath") ); - if( ! ca_path.empty()) + else if ( verify == "no" ) { - if( !PathInfo(ca_path).isDir() || ! ca_path.absolute()) - ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_capath path")); - else - s.setCertificateAuthoritiesPath(ca_path); + s.setVerifyPeerEnabled( false ); + s.setVerifyHostEnabled( false ); } - - Pathname client_cert( url.getQueryParam("ssl_clientcert") ); - if( ! client_cert.empty()) + else { - if( !PathInfo(client_cert).isFile() || !client_cert.absolute()) - ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_clientcert file")); - else - s.setClientCertificatePath(client_cert); + std::vector flags; + str::split( verify, std::back_inserter(flags), "," ); + for ( const auto & flag : flags ) + { + if ( flag == "host" ) + s.setVerifyHostEnabled( true ); + else if ( flag == "peer" ) + s.setVerifyPeerEnabled( true ); + else + ZYPP_THROW(MediaBadUrlException(url, "Unknown ssl_verify flag "+flag)); + } + } + } + { + Pathname ca_path { url.getQueryParam("ssl_capath") }; + if( ! ca_path.empty() ) + { + if( ! PathInfo(ca_path).isDir() || ! ca_path.absolute() ) + ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_capath path")); + else + s.setCertificateAuthoritiesPath( std::move(ca_path) ); } - Pathname client_key( url.getQueryParam("ssl_clientkey") ); - if( ! client_key.empty()) + } + { + Pathname client_cert { url.getQueryParam("ssl_clientcert") }; + if( ! client_cert.empty() ) { - if( !PathInfo(client_key).isFile() || !client_key.absolute()) - ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_clientkey file")); - else - s.setClientKeyPath(client_key); + if( ! PathInfo(client_cert).isFile() || ! client_cert.absolute() ) + ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_clientcert file")); + else + s.setClientCertificatePath( std::move(client_cert) ); } - - param = url.getQueryParam( "proxy" ); + } + { + Pathname client_key { url.getQueryParam("ssl_clientkey") }; + if( ! client_key.empty() ) + { + if( ! PathInfo(client_key).isFile() || ! client_key.absolute() ) + ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_clientkey file")); + else + s.setClientKeyPath( std::move(client_key) ); + } + } + { + std::string param { url.getQueryParam( "proxy" ) }; if ( ! param.empty() ) { - if ( param == EXPLICITLY_NO_PROXY ) { - // Workaround TransferSettings shortcoming: With an - // empty proxy string, code will continue to look for - // valid proxy settings. So set proxy to some non-empty - // string, to indicate it has been explicitly disabled. - s.setProxy(EXPLICITLY_NO_PROXY); - s.setProxyEnabled(false); - } - else { - string proxyport( url.getQueryParam( "proxyport" ) ); - if ( ! proxyport.empty() ) { - param += ":" + proxyport; - } - s.setProxy(param); - s.setProxyEnabled(true); - } + if ( param == EXPLICITLY_NO_PROXY ) { + // Workaround TransferSettings shortcoming: With an + // empty proxy string, code will continue to look for + // valid proxy settings. So set proxy to some non-empty + // string, to indicate it has been explicitly disabled. + s.setProxy(EXPLICITLY_NO_PROXY); + s.setProxyEnabled(false); + } + else { + const string & proxyport { url.getQueryParam( "proxyport" ) }; + if ( ! proxyport.empty() ) { + param += ":"; + param += proxyport; + } + s.setProxy( std::move(param) ); + s.setProxyEnabled( true ); + } } - - param = url.getQueryParam( "proxyuser" ); + } + { + std::string param { url.getQueryParam( "proxyuser" ) }; if ( ! param.empty() ) { - s.setProxyUsername(param); - s.setProxyPassword(url.getQueryParam( "proxypass" )); + s.setProxyUsername( std::move(param) ); + s.setProxyPassword( url.getQueryParam( "proxypass" ) ); } - + } + { // HTTP authentication type - param = url.getQueryParam("auth"); - if (!param.empty() && (url.getScheme() == "http" || url.getScheme() == "https")) + std::string param { url.getQueryParam("auth") }; + if ( ! param.empty() && (url.getScheme() == "http" || url.getScheme() == "https") ) { - try - { - CurlAuthData::auth_type_str2long(param); // check if we know it - } - catch (MediaException & ex_r) - { - DBG << "Rethrowing as MediaUnauthorizedException."; - ZYPP_THROW(MediaUnauthorizedException(url, ex_r.msg(), "", "")); - } - s.setAuthType(param); + try + { + CurlAuthData::auth_type_str2long (param ); // check if we know it + } + catch ( const MediaException & ex_r ) + { + DBG << "Rethrowing as MediaUnauthorizedException."; + ZYPP_THROW(MediaUnauthorizedException(url, ex_r.msg(), "", "")); + } + s.setAuthType( std::move(param) ); } - + } + { // workarounds - param = url.getQueryParam("head_requests"); - if( !param.empty() && param == "no" ) - s.setHeadRequestsAllowed(false); + const std::string & param { url.getQueryParam("head_requests") }; + if( ! param.empty() && param == "no" ) + s.setHeadRequestsAllowed( false ); + } } /** @@ -512,8 +523,7 @@ static const char *const agentString() // is guessed. static const std::string _value( str::form( - "ZYpp %s (curl %s) %s" - , VERSION + "ZYpp " LIBZYPP_VERSION_STRING " (curl %s) %s" , curl_version_info(CURLVERSION_NOW)->version , Target::targetDistribution( Pathname()/*guess root*/ ).c_str() ) diff --git a/zypp/media/MediaUserAuth.h b/zypp/media/MediaUserAuth.h index 4a3f429..27e47fb 100644 --- a/zypp/media/MediaUserAuth.h +++ b/zypp/media/MediaUserAuth.h @@ -120,8 +120,8 @@ public: _auth_type_str = auth_type_long2str(auth_type); } - long authType() { return _auth_type; } const - std::string authTypeAsString() { return _auth_type_str; } const + long authType() const { return _auth_type; } + std::string authTypeAsString() const { return _auth_type_str; } std::string getUserPwd() const { return username() + ":" + password(); } diff --git a/zypp/media/TransferSettings.cc b/zypp/media/TransferSettings.cc index 81262c7..de2092a 100644 --- a/zypp/media/TransferSettings.cc +++ b/zypp/media/TransferSettings.cc @@ -16,325 +16,251 @@ using namespace std; namespace zypp { -namespace media -{ + namespace media + { -class TransferSettings::Impl -{ -public: - Impl() - : _useproxy(false) - , _timeout(0) - , _connect_timeout(0) - , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections()) - , _minDownloadSpeed(ZConfig::instance().download_min_download_speed()) - , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed()) - , _maxSilentTries(ZConfig::instance().download_max_silent_tries()) - , _verify_host(false) - , _verify_peer(false) - , _ca_path("/etc/ssl/certs") - , _head_requests_allowed(true) + class TransferSettings::Impl + { + public: + Impl() + : _useproxy(false) + , _timeout(0) + , _connect_timeout(0) + , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections()) + , _minDownloadSpeed(ZConfig::instance().download_min_download_speed()) + , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed()) + , _maxSilentTries(ZConfig::instance().download_max_silent_tries()) + , _verify_host(false) + , _verify_peer(false) + , _ca_path("/etc/ssl/certs") + , _head_requests_allowed(true) + {} + + virtual ~Impl() + {} + + /** Offer default Impl. */ + static shared_ptr nullimpl() + { + static shared_ptr _nullimpl( new Impl ); + return _nullimpl; + } + + private: + friend Impl * rwcowClone( const Impl * rhs ); + /** clone for RWCOW_pointer */ + Impl * clone() const + { return new Impl( *this ); } + + public: + vector _headers; + string _useragent; + string _username; + string _password; + bool _useproxy; + string _proxy; + string _proxy_username; + string _proxy_password; + string _authtype; + long _timeout; + long _connect_timeout; + Url _url; + Pathname _targetdir; + + long _maxConcurrentConnections; + long _minDownloadSpeed; + long _maxDownloadSpeed; + long _maxSilentTries; + + bool _verify_host; + bool _verify_peer; + Pathname _ca_path; + Pathname _client_cert_path; + Pathname _client_key_path; + + // workarounds + bool _head_requests_allowed; + }; + + TransferSettings::TransferSettings() + : _impl(new TransferSettings::Impl()) {} - virtual ~Impl() - {} + void TransferSettings::reset() + { _impl.reset(new TransferSettings::Impl()); } + + + void TransferSettings::addHeader( std::string && val_r ) + { if ( ! val_r.empty() ) _impl->_headers.push_back( std::move(val_r) ); } + + TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const + { return _impl->_headers.begin(); } + + TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const + { return _impl->_headers.end(); } + - /** Offer default Impl. */ - static shared_ptr nullimpl() + void TransferSettings::setUserAgentString( std::string && val_r ) + { _impl->_useragent = std::move(val_r); } + + std::string TransferSettings::userAgentString() const + { return _impl->_useragent; } + + + void TransferSettings::setUsername( std::string && val_r ) + { _impl->_username = std::move(val_r); } + + std::string TransferSettings::username() const + { return _impl->_username; } + + void TransferSettings::setPassword( std::string && val_r ) + { _impl->_password = std::move(val_r); } + + std::string TransferSettings::password() const + { return _impl->_password; } + + std::string TransferSettings::userPassword() const { - static shared_ptr _nullimpl( new Impl ); - return _nullimpl; + string userpwd = username(); + if ( password().size() ) { + userpwd += ":" + password(); + } + return userpwd; } -private: - friend Impl * rwcowClone( const Impl * rhs ); - /** clone for RWCOW_pointer */ - Impl * clone() const - { return new Impl( *this ); } - -public: - vector _headers; - string _useragent; - string _username; - string _password; - bool _useproxy; - string _proxy; - string _proxy_username; - string _proxy_password; - string _authtype; - long _timeout; - long _connect_timeout; - Url _url; - Pathname _targetdir; - - long _maxConcurrentConnections; - long _minDownloadSpeed; - long _maxDownloadSpeed; - long _maxSilentTries; - - bool _verify_host; - bool _verify_peer; - Pathname _ca_path; - Pathname _client_cert_path; - Pathname _client_key_path; - - // workarounds - bool _head_requests_allowed; -}; - -TransferSettings::TransferSettings() - : _impl(new TransferSettings::Impl()) -{ + void TransferSettings::setAnonymousAuth() + { + setUsername("anonymous"); + setPassword("yast@" LIBZYPP_VERSION_STRING); + } -} -void TransferSettings::reset() -{ - _impl.reset(new TransferSettings::Impl()); -} + void TransferSettings::setProxyEnabled( bool enabled ) + { _impl->_useproxy = enabled; } -void TransferSettings::addHeader( const std::string &header ) -{ - if ( ! header.empty() ) - _impl->_headers.push_back(header); -} + bool TransferSettings::proxyEnabled() const + { return _impl->_useproxy; } -TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const -{ - return _impl->_headers.begin(); -} -TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const -{ - return _impl->_headers.end(); -} - -void TransferSettings::setUserAgentString( const std::string &agent ) -{ - _impl->_useragent = agent; -} + void TransferSettings::setProxy( std::string && val_r ) + { _impl->_proxy = std::move(val_r); } -std::string TransferSettings::userAgentString() const -{ - return _impl->_useragent; -} + std::string TransferSettings::proxy() const + { return _impl->_proxy; } -void TransferSettings::setUsername( const std::string &username ) -{ - _impl->_username = username; -} -std::string TransferSettings::username() const -{ - return _impl->_username; -} + void TransferSettings::setProxyUsername( std::string && val_r ) + { _impl->_proxy_username = std::move(val_r); } -void TransferSettings::setPassword( const std::string &password ) -{ - _impl->_password = password; -} + std::string TransferSettings::proxyUsername() const + { return _impl->_proxy_username; } -void TransferSettings::setAnonymousAuth() -{ - setUsername("anonymous"); - string id = "yast@"; - setPassword(id + VERSION); -} + void TransferSettings::setProxyPassword( std::string && val_r ) + { _impl->_proxy_password = std::move(val_r); } -std::string TransferSettings::password() const -{ - return _impl->_password; -} + std::string TransferSettings::proxyPassword() const + { return _impl->_proxy_password; } -std::string TransferSettings::userPassword() const -{ - string userpwd = username(); - if ( password().size() ) { - userpwd += ":" + password(); + std::string TransferSettings::proxyUserPassword() const + { + string userpwd = proxyUsername(); + if ( proxyPassword().size() ) { + userpwd += ":" + proxyPassword(); + } + return userpwd; } - return userpwd; -} -void TransferSettings::setProxyEnabled( bool enabled ) -{ - _impl->_useproxy = enabled; -} -bool TransferSettings::proxyEnabled() const -{ - return _impl->_useproxy; -} + void TransferSettings::setTimeout( long t ) + { _impl->_timeout = t; } -void TransferSettings::setProxy( const std::string &proxy ) -{ - _impl->_proxy = proxy; -} + long TransferSettings::timeout() const + { return _impl->_timeout; } -std::string TransferSettings::proxy() const -{ - return _impl->_proxy; -} -void TransferSettings::setProxyUsername( const std::string &proxyuser ) -{ - _impl->_proxy_username = proxyuser; -} + void TransferSettings::setConnectTimeout( long t ) + { _impl->_connect_timeout = t; } -std::string TransferSettings::proxyUsername() const -{ - return _impl->_proxy_username; -} + long TransferSettings::connectTimeout() const + { return _impl->_connect_timeout; } -void TransferSettings::setProxyPassword( const std::string &proxypass ) -{ - _impl->_proxy_password = proxypass; -} -std::string TransferSettings::proxyPassword() const -{ - return _impl->_proxy_password; -} + void TransferSettings::setMaxConcurrentConnections( long v ) + { _impl->_maxConcurrentConnections = v; } -std::string TransferSettings::proxyUserPassword() const -{ - string userpwd = proxyUsername(); - if ( proxyPassword().size() ) { - userpwd += ":" + proxyPassword(); - } - return userpwd; -} + long TransferSettings::maxConcurrentConnections() const + { return _impl->_maxConcurrentConnections; } -void TransferSettings::setTimeout( long t ) -{ - _impl->_timeout = t; -} -long TransferSettings::timeout() const -{ - return _impl->_timeout; -} + void TransferSettings::setMinDownloadSpeed( long v ) + { _impl->_minDownloadSpeed = v; } -void TransferSettings::setConnectTimeout( long t ) -{ - _impl->_connect_timeout = t; -} + long TransferSettings::minDownloadSpeed() const + { return _impl->_minDownloadSpeed; } -long TransferSettings::connectTimeout() const -{ - return _impl->_connect_timeout; -} -long TransferSettings::maxConcurrentConnections() const -{ - return _impl->_maxConcurrentConnections; -} + void TransferSettings::setMaxDownloadSpeed( long v ) + { _impl->_maxDownloadSpeed = v; } -void TransferSettings::setMaxConcurrentConnections(long v) -{ - _impl->_maxConcurrentConnections = v; -} + long TransferSettings::maxDownloadSpeed() const + { return _impl->_maxDownloadSpeed; } -long TransferSettings::minDownloadSpeed() const -{ - return _impl->_minDownloadSpeed; -} -void TransferSettings::setMinDownloadSpeed(long v) -{ - _impl->_minDownloadSpeed = v; -} + void TransferSettings::setMaxSilentTries( long v ) + { _impl->_maxSilentTries = v; } -long TransferSettings::maxDownloadSpeed() const -{ - return _impl->_maxDownloadSpeed; -} + long TransferSettings::maxSilentTries() const + { return _impl->_maxSilentTries; } -void TransferSettings::setMaxDownloadSpeed(long v) -{ - _impl->_maxDownloadSpeed = v; -} -long TransferSettings::maxSilentTries() const -{ - return _impl->_maxSilentTries; -} + void TransferSettings::setVerifyHostEnabled( bool enabled ) + { _impl->_verify_host = enabled; } -void TransferSettings::setMaxSilentTries(long v) -{ - _impl->_maxSilentTries = v; -} + bool TransferSettings::verifyHostEnabled() const + { return _impl->_verify_host; } -bool TransferSettings::verifyHostEnabled() const -{ - return _impl->_verify_host; -} -void TransferSettings::setVerifyHostEnabled( bool enabled ) -{ - _impl->_verify_host = enabled; -} + void TransferSettings::setVerifyPeerEnabled( bool enabled ) + { _impl->_verify_peer = enabled; } -bool TransferSettings::verifyPeerEnabled() const -{ - return _impl->_verify_peer; -} + bool TransferSettings::verifyPeerEnabled() const + { return _impl->_verify_peer; } -Pathname TransferSettings::clientCertificatePath() const -{ - return _impl->_client_cert_path; -} -void TransferSettings::setClientCertificatePath( const zypp::Pathname &path ) -{ - _impl->_client_cert_path = path; -} + void TransferSettings::setClientCertificatePath( Pathname && val_r ) + { _impl->_client_cert_path = std::move(val_r); } -Pathname TransferSettings::clientKeyPath() const -{ - return _impl->_client_key_path; -} + Pathname TransferSettings::clientCertificatePath() const + { return _impl->_client_cert_path; } -void TransferSettings::setClientKeyPath( const zypp::Pathname &path ) -{ - _impl->_client_key_path = path; -} + void TransferSettings::setClientKeyPath( Pathname && val_r ) + { _impl->_client_key_path = std::move(val_r); } -void TransferSettings::setVerifyPeerEnabled( bool enabled ) -{ - _impl->_verify_peer = enabled; -} + Pathname TransferSettings::clientKeyPath() const + { return _impl->_client_key_path; } -Pathname TransferSettings::certificateAuthoritiesPath() const -{ - return _impl->_ca_path; -} -void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path ) -{ - _impl->_ca_path = path; -} + void TransferSettings::setCertificateAuthoritiesPath( Pathname && val_r ) + { _impl->_ca_path = std::move(val_r); } -void TransferSettings::setAuthType( const std::string &authtype) -{ - _impl->_authtype = authtype; -} + Pathname TransferSettings::certificateAuthoritiesPath() const + { return _impl->_ca_path; } -std::string TransferSettings::authType() const -{ - return _impl->_authtype; -} -void TransferSettings::setHeadRequestsAllowed(bool allowed) -{ - _impl->_head_requests_allowed = allowed; -} + void TransferSettings::setAuthType( std::string && val_r ) + { _impl->_authtype = std::move(val_r); } -bool TransferSettings::headRequestsAllowed() const -{ - return _impl->_head_requests_allowed; -} + std::string TransferSettings::authType() const + { return _impl->_authtype; } + + + void TransferSettings::setHeadRequestsAllowed( bool allowed ) + { _impl->_head_requests_allowed = allowed; } + + bool TransferSettings::headRequestsAllowed() const + { return _impl->_head_requests_allowed; } -} // ns media -} // ns zypp + } // namespace media +} // namespace zypp diff --git a/zypp/media/TransferSettings.h b/zypp/media/TransferSettings.h index 759bd5b..9c43317 100644 --- a/zypp/media/TransferSettings.h +++ b/zypp/media/TransferSettings.h @@ -11,275 +11,186 @@ namespace zypp { -namespace media -{ + namespace media + { -/** - * Holds transfer setting - */ -class TransferSettings -{ -public: - /** - * Constructs a transfer program cmd line access. - */ - TransferSettings(); - - /** - * Constructs the settings from a url object where. - * authentication/proxy information can be extracted - * from the url - */ - TransferSettings( const zypp::Url &url ); - - typedef std::vector Headers; - - /** - * reset the settings to the defaults - */ - void reset(); - - /** - * add a header, on the form "Foo: Bar" - */ - void addHeader( const std::string &header ); - - /** - * begin iterators to additional headers - */ - Headers::const_iterator headersBegin() const; - - /** - * end iterators to additional headers - */ - Headers::const_iterator headersEnd() const; - - /** - * sets the user agent ie: "Mozilla v3" - */ - void setUserAgentString( const std::string &agent ); - - /** - * user agent string - */ - std::string userAgentString() const; - - /** - * sets the auth username - */ - void setUsername( const std::string &username ); - - /** - * auth username - */ - std::string username() const; - - /** - * sets the auth password - */ - void setPassword( const std::string &password ); - - /** - * auth password - */ - std::string password() const; - - /** - * returns the user and password as - * a user:pass string - */ - std::string userPassword() const; - - /** - * sets anonymous authentication (ie: for ftp) - */ - void setAnonymousAuth(); - - /** - * whether the proxy is used or not - */ - void setProxyEnabled( bool enabled ); - - /** - * proxy is enabled - */ - bool proxyEnabled() const; - - /** - * proxy to use if it is enabled - */ - void setProxy( const std::string &proxyhost ); - - /** - * proxy host - */ - std::string proxy() const; - - /** - * sets the proxy user - */ - void setProxyUsername( const std::string &proxyuser ); - - /** - * proxy auth username - */ - std::string proxyUsername() const; - - /** - * sets the proxy password - */ - void setProxyPassword( const std::string &proxypass ); - - /** - * proxy auth password - */ - std::string proxyPassword() const; - - /** - * returns the proxy user and password as - * a user:pass string - */ - std::string proxyUserPassword() const; - - /** - * set the connect timeout - */ - void setConnectTimeout( long t ); - - /** - * connection timeout - */ - long connectTimeout() const; - - /** - * set the transfer timeout - */ - void setTimeout( long t ); - - /** - * transfer timeout - */ - long timeout() const; - - /** - * Maximum number of concurrent connections for a single transfer - */ - long maxConcurrentConnections() const; - - /** - * Set maximum number of concurrent connections for a single transfer - */ - void setMaxConcurrentConnections(long v); - - /** - * Minimum download speed (bytes per second) - * until the connection is dropped - */ - long minDownloadSpeed() const; - - /** - * Set minimum download speed (bytes per second) - * until the connection is dropped - */ - void setMinDownloadSpeed(long v); - - /** - * Maximum download speed (bytes per second) - */ - long maxDownloadSpeed() const; - - /** - * Set max download speed (bytes per second) - */ - void setMaxDownloadSpeed(long v); - - /** - * Maximum silent retries - */ - long maxSilentTries() const; - - /** - * Set maximum silent retries - */ - void setMaxSilentTries(long v); - - /** - * Whether to verify host for ssl - */ - bool verifyHostEnabled() const; - - /** - * Sets whether to verify host for ssl - */ - void setVerifyHostEnabled( bool enabled ); - - /** - * Whether to verify peer for ssl - */ - bool verifyPeerEnabled() const; - - /** - * Sets whether to verify host for ssl - */ - void setVerifyPeerEnabled( bool enabled ); - - /** - * SSL certificate authorities path - * ( default: /etc/ssl/certs ) - */ - Pathname certificateAuthoritiesPath() const; - - /** - * Sets the SSL certificate authorities path - */ - void setCertificateAuthoritiesPath( const zypp::Pathname &path ); - - /** - * set the allowed authentication types - */ - void setAuthType( const std::string &authtype ); - - /** - * get the allowed authentication types - */ - std::string authType() const; - - /** - * set whether HEAD requests are allowed - */ - void setHeadRequestsAllowed(bool allowed); - - /** - * whether HEAD requests are allowed - */ - bool headRequestsAllowed() const; - - /** - * SSL client certificate file - */ - Pathname clientCertificatePath() const; - - /** - * Sets the SSL client certificate file - */ - void setClientCertificatePath( const zypp::Pathname &path ); - - /** - * SSL client key file - */ - Pathname clientKeyPath() const; - - /** - * Sets the SSL client key file - */ - void setClientKeyPath( const zypp::Pathname &path ); - -protected: - class Impl; - RWCOW_pointer _impl; -}; - -} // ns media -} // ns zypp + /** + * Holds transfer setting + */ + class TransferSettings + { + public: + /** Constructs a transfer program cmd line access. */ + TransferSettings(); + + typedef std::vector Headers; + + /** reset the settings to the defaults */ + void reset(); + + + /** add a header, on the form "Foo: Bar" */ + void addHeader( std::string && val_r ); + + /** begin iterators to additional headers */ + Headers::const_iterator headersBegin() const; + + /** end iterators to additional headers */ + Headers::const_iterator headersEnd() const; + + + /** sets the user agent ie: "Mozilla v3" */ + void setUserAgentString( std::string && val_r ); + + /** user agent string */ + std::string userAgentString() const; + + + /** sets the auth username */ + void setUsername( std::string && val_r ); + + /** auth username */ + std::string username() const; + + /** sets the auth password */ + void setPassword( std::string && val_r ); + + /** auth password */ + std::string password() const; + + /** returns the user and password as a user:pass string */ + std::string userPassword() const; + + /** sets anonymous authentication (ie: for ftp) */ + void setAnonymousAuth(); + + + /** whether the proxy is used or not */ + void setProxyEnabled( bool enabled ); + + /** proxy is enabled */ + bool proxyEnabled() const; + + + /** proxy to use if it is enabled */ + void setProxy( std::string && val_r ); + + /** proxy host */ + std::string proxy() const; + + + /** sets the proxy user */ + void setProxyUsername( std::string && val_r ); + + /** proxy auth username */ + std::string proxyUsername() const; + + /** sets the proxy password */ + void setProxyPassword( std::string && val_r ); + + /** proxy auth password */ + std::string proxyPassword() const; + + /** returns the proxy user and password as a user:pass string */ + std::string proxyUserPassword() const; + + + /** set the connect timeout */ + void setConnectTimeout( long t ); + + /** connection timeout */ + long connectTimeout() const; + + + /** set the transfer timeout */ + void setTimeout( long t ); + + /** transfer timeout */ + long timeout() const; + + + /** Set maximum number of concurrent connections for a single transfer */ + void setMaxConcurrentConnections(long v); + + /** Maximum number of concurrent connections for a single transfer */ + long maxConcurrentConnections() const; + + + /** Set minimum download speed (bytes per second) until the connection is dropped */ + void setMinDownloadSpeed(long v); + + /** Minimum download speed (bytes per second) until the connection is dropped */ + long minDownloadSpeed() const; + + + /** Set max download speed (bytes per second) */ + void setMaxDownloadSpeed(long v); + + /** Maximum download speed (bytes per second) */ + long maxDownloadSpeed() const; + + + /** Set maximum silent retries */ + void setMaxSilentTries(long v); + + /** Maximum silent retries */ + long maxSilentTries() const; + + + /** Sets whether to verify host for ssl */ + void setVerifyHostEnabled( bool enabled ); + + /** Whether to verify host for ssl */ + bool verifyHostEnabled() const; + + + /** Sets whether to verify host for ssl */ + void setVerifyPeerEnabled( bool enabled ); + + /** Whether to verify peer for ssl */ + bool verifyPeerEnabled() const; + + + /** Sets the SSL certificate authorities path */ + void setCertificateAuthoritiesPath( Pathname && val_r ); + + /** SSL certificate authorities path ( default: /etc/ssl/certs ) */ + Pathname certificateAuthoritiesPath() const; + + + /** set the allowed authentication types */ + void setAuthType( std::string && val_r ); + + /** get the allowed authentication types */ + std::string authType() const; + + + /** set whether HEAD requests are allowed */ + void setHeadRequestsAllowed(bool allowed); + + /** whether HEAD requests are allowed */ + bool headRequestsAllowed() const; + + + /** Sets the SSL client certificate file */ + void setClientCertificatePath( Pathname && val_r ); + + /** SSL client certificate file */ + Pathname clientCertificatePath() const; + + + /** Sets the SSL client key file */ + void setClientKeyPath( Pathname && val_r ); + + /** SSL client key file */ + Pathname clientKeyPath() const; + + protected: + class Impl; + RWCOW_pointer _impl; + }; + + } // namespace media +} // namespece zypp #endif diff --git a/zypp/solver/detail/SATResolver.cc b/zypp/solver/detail/SATResolver.cc index 737cdc4..8b63a45 100644 --- a/zypp/solver/detail/SATResolver.cc +++ b/zypp/solver/detail/SATResolver.cc @@ -437,9 +437,11 @@ SATResolver::solving(const CapabilitySet & requires_caps, // get Solvables to be installed... sat::SolvableQueue decisionq; solver_get_decisionqueue( _satSolver, decisionq ); - for ( sat::Solvable::IdType slvid : decisionq ) + for ( sat::detail::IdType id : decisionq ) { - sat::Solvable slv { slvid }; + if ( id < 0 ) + continue; + sat::Solvable slv { id }; // get product buddies (they carry the weakremover)... static const Capability productCap { "product()" }; if ( slv && slv.provides().matches( productCap ) ) @@ -456,7 +458,7 @@ SATResolver::solving(const CapabilitySet & requires_caps, } // PIN product - a safety net to prevent cleanup from changing the decision for this product queue_push( &(_jobQueue), SOLVER_INSTALL | SOLVER_SOLVABLE ); - queue_push( &(_jobQueue), slvid ); + queue_push( &(_jobQueue), id ); resolve = true; } } @@ -479,8 +481,12 @@ SATResolver::solving(const CapabilitySet & requires_caps, solver_get_decisionqueue(_satSolver, &decisionq); for ( int i = 0; i < decisionq.count; ++i ) { - sat::Solvable slv( decisionq.elements[i] ); - if ( !slv || slv.isSystem() ) + Id p = decisionq.elements[i]; + if ( p < 0 ) + continue; + + sat::Solvable slv { p }; + if ( ! slv || slv.isSystem() ) continue; PoolItem poolItem( slv ); @@ -886,19 +892,15 @@ void SATResolver::doUpdate() solver_get_decisionqueue(_satSolver, &decisionq); for (int i = 0; i < decisionq.count; i++) { - Id p; - p = decisionq.elements[i]; - if (p < 0 || !sat::Solvable(p)) + Id p = decisionq.elements[i]; + if ( p < 0 ) continue; - if (sat::Solvable(p).repository().get() == _satSolver->pool->installed) + + sat::Solvable solv { p }; + if ( ! solv || solv.isSystem() ) continue; - PoolItem poolItem = _pool.find (sat::Solvable(p)); - if (poolItem) { - SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER); - } else { - ERR << "id " << p << " not found in ZYPP pool." << endl; - } + SATSolutionToPool( PoolItem(solv), ResStatus::toBeInstalled, ResStatus::SOLVER ); } queue_free(&decisionq); diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 3fd990b..ab0dc34 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -62,6 +62,40 @@ using namespace std; /////////////////////////////////////////////////////////////////// +extern "C" +{ +#include +} +namespace zypp +{ + namespace target + { + inline std::string rpmDbStateHash( const Pathname & root_r ) + { + std::string ret; + AutoDispose state { ::rpm_state_create( sat::Pool::instance().get(), root_r.c_str() ), ::rpm_state_free }; + AutoDispose chk { ::solv_chksum_create( REPOKEY_TYPE_SHA1 ), []( Chksum *chk ) -> void { + ::solv_chksum_free( chk, nullptr ); + } }; + if ( ::rpm_hash_database_state( state, chk ) == 0 ) + { + int md5l; + const unsigned char * md5 = ::solv_chksum_get( chk, &md5l ); + ret = ::pool_bin2hex( sat::Pool::instance().get(), md5, md5l ); + } + else + WAR << "rpm_hash_database_state failed" << endl; + return ret; + } + + inline RepoStatus rpmDbRepoStatus( const Pathname & root_r ) + { return RepoStatus( rpmDbStateHash( root_r ), Date() ); } + + } // namespace target +} // namespace +/////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -689,7 +723,7 @@ namespace zypp , _autoInstalledFile( home() / "AutoInstalled" ) , _hardLocksFile( Pathname::assertprefix( _root, ZConfig::instance().locksFile() ) ) { - _rpm.initDatabase( root_r, Pathname(), doRebuild_r ); + _rpm.initDatabase( root_r, doRebuild_r ); HistoryLog::setRoot(_root); @@ -843,7 +877,7 @@ namespace zypp bool build_rpm_solv = true; // lets see if the rpm solv cache exists - RepoStatus rpmstatus( RepoStatus(_root/"var/lib/rpm/Name") && RepoStatus(_root/"etc/products.d") ); + RepoStatus rpmstatus( rpmDbRepoStatus(_root) && RepoStatus(_root/"etc/products.d") ); bool solvexisted = PathInfo(rpmsolv).isExist(); if ( solvexisted ) @@ -1695,12 +1729,6 @@ namespace zypp return _rpm.hasFile(path_str, name_str); } - - Date TargetImpl::timestamp() const - { - return _rpm.timestamp(); - } - /////////////////////////////////////////////////////////////////// namespace { diff --git a/zypp/target/TargetImpl.h b/zypp/target/TargetImpl.h index 6658900..26f7341 100644 --- a/zypp/target/TargetImpl.h +++ b/zypp/target/TargetImpl.h @@ -150,9 +150,6 @@ namespace zypp std::string whoOwnsFile (const std::string & path_str) const { return _rpm.whoOwnsFile (path_str); } - /** return the last modification date of the target */ - Date timestamp() const; - /** \copydoc Target::baseProduct() */ Product::constPtr baseProduct() const; diff --git a/zypp/target/rpm/RpmDb.cc b/zypp/target/rpm/RpmDb.cc index 7203d79..00240a4 100644 --- a/zypp/target/rpm/RpmDb.cc +++ b/zypp/target/rpm/RpmDb.cc @@ -33,11 +33,13 @@ extern "C" #include "zypp/base/String.h" #include "zypp/base/Gettext.h" #include "zypp/base/LocaleGuard.h" +#include "zypp/base/DtorReset.h" #include "zypp/Date.h" #include "zypp/Pathname.h" #include "zypp/PathInfo.h" #include "zypp/PublicKey.h" +#include "zypp/ProgressData.h" #include "zypp/target/rpm/RpmDb.h" #include "zypp/target/rpm/RpmCallbacks.h" @@ -183,37 +185,6 @@ inline std::string stringPath( const Pathname & root_r, const Pathname & sub_r ) return librpmDb::stringPath( root_r, sub_r ); } -/****************************************************************** - ** - ** - ** FUNCTION NAME : operator<< - ** FUNCTION TYPE : std::ostream & -*/ -std::ostream & operator<<( std::ostream & str, const RpmDb::DbStateInfoBits & obj ) -{ - if ( obj == RpmDb::DbSI_NO_INIT ) - { - str << "NO_INIT"; - } - else - { -#define ENUM_OUT(B,C) str << ( obj & RpmDb::B ? C : '-' ) - str << "V4("; - ENUM_OUT( DbSI_HAVE_V4, 'X' ); - ENUM_OUT( DbSI_MADE_V4, 'c' ); - ENUM_OUT( DbSI_MODIFIED_V4, 'm' ); - str << ")V3("; - ENUM_OUT( DbSI_HAVE_V3, 'X' ); - ENUM_OUT( DbSI_HAVE_V3TOV4, 'B' ); - ENUM_OUT( DbSI_MADE_V3TOV4, 'c' ); - str << ")"; -#undef ENUM_OUT - } - return str; -} - - - /////////////////////////////////////////////////////////////////// // // CLASS NAME : RpmDb @@ -231,11 +202,8 @@ std::ostream & operator<<( std::ostream & str, const RpmDb::DbStateInfoBits & ob // METHOD TYPE : Constructor // RpmDb::RpmDb() - : _dbStateInfo( DbSI_NO_INIT ) -#warning Check for obsolete memebers - , _backuppath ("/var/adm/backup") + : _backuppath ("/var/adm/backup") , _packagebackups(false) - , _warndirexists(false) { process = 0; exit_code = -1; @@ -261,23 +229,6 @@ RpmDb::~RpmDb() sKeyRingReceiver.reset(); } -Date RpmDb::timestamp() const -{ - Date ts_rpm; - - Pathname db_path; - if ( dbPath().empty() ) - db_path = "/var/lib/rpm"; - else - db_path = dbPath(); - - PathInfo rpmdb_info(root() + db_path + "/Packages"); - - if ( rpmdb_info.isExist() ) - return rpmdb_info.mtime(); - else - return Date::now(); -} /////////////////////////////////////////////////////////////////// // // @@ -286,27 +237,7 @@ Date RpmDb::timestamp() const // std::ostream & RpmDb::dumpOn( std::ostream & str ) const { - str << "RpmDb["; - - if ( _dbStateInfo == DbSI_NO_INIT ) - { - str << "NO_INIT"; - } - else - { -#define ENUM_OUT(B,C) str << ( _dbStateInfo & B ? C : '-' ) - str << "V4("; - ENUM_OUT( DbSI_HAVE_V4, 'X' ); - ENUM_OUT( DbSI_MADE_V4, 'c' ); - ENUM_OUT( DbSI_MODIFIED_V4, 'm' ); - str << ")V3("; - ENUM_OUT( DbSI_HAVE_V3, 'X' ); - ENUM_OUT( DbSI_HAVE_V3TOV4, 'B' ); - ENUM_OUT( DbSI_MADE_V3TOV4, 'c' ); - str << "): " << stringPath( _root, _dbPath ); -#undef ENUM_OUT - } - return str << "]"; + return str << "RpmDb[" << stringPath( _root, _dbPath ) << "]"; } /////////////////////////////////////////////////////////////////// @@ -315,7 +246,7 @@ std::ostream & RpmDb::dumpOn( std::ostream & str ) const // METHOD NAME : RpmDb::initDatabase // METHOD TYPE : PMError // -void RpmDb::initDatabase( Pathname root_r, Pathname dbPath_r, bool doRebuild_r ) +void RpmDb::initDatabase( Pathname root_r, bool doRebuild_r ) { /////////////////////////////////////////////////////////////////// // Check arguments @@ -325,17 +256,19 @@ void RpmDb::initDatabase( Pathname root_r, Pathname dbPath_r, bool doRebuild_r ) if ( root_r.empty() ) root_r = "/"; - if ( dbPath_r.empty() ) - dbPath_r = "/var/lib/rpm"; + // NOTE: Former argument, but now locked to "/var/lib/rpm". + // A custom dbPath is not actually needed and would only work + // reliably if libsolv also supports it. By now no further + // cleanup in the code. + const Pathname & dbPath_r { librpmDb::defaultDbPath() }; - if ( ! (root_r.absolute() && dbPath_r.absolute()) ) + if ( ! root_r.absolute() ) { ERR << "Illegal root or dbPath: " << stringPath( root_r, dbPath_r ) << endl; ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r)); } - if ( dbPath_r == "/var/lib/rpm" - && ! PathInfo( root_r/"/var/lib/rpm" ).isExist() + if ( ! PathInfo( root_r/"/var/lib/rpm" ).isExist() && PathInfo( root_r/"/usr/lib/sysimage/rpm" ).isDir() ) { WAR << "Rpm package was deleted? Injecting missing rpmdb compat symlink." << endl; @@ -372,56 +305,23 @@ void RpmDb::initDatabase( Pathname root_r, Pathname dbPath_r, bool doRebuild_r ) return; } - DbStateInfoBits info = DbSI_NO_INIT; try { - internal_initDatabase( root_r, dbPath_r, info ); + // creates dbdir and empty rpm database if not present + librpmDb::dbAccess( root_r ); } catch (const RpmException & excpt_r) { ZYPP_CAUGHT(excpt_r); librpmDb::blockAccess(); - ERR << "Cleanup on error: state " << info << endl; - - if ( dbsi_has( info, DbSI_MADE_V4 ) ) - { - // remove the newly created rpm4 database and - // any backup created on conversion. - removeV4( root_r + dbPath_r, dbsi_has( info, DbSI_MADE_V3TOV4 ) ); - } ZYPP_RETHROW(excpt_r); } - if ( dbsi_has( info, DbSI_HAVE_V3 ) ) - { - if ( root_r == "/" || dbsi_has( info, DbSI_MODIFIED_V4 ) ) - { - // Move obsolete rpm3 database beside. - MIL << "Cleanup: state " << info << endl; - removeV3( root_r + dbPath_r, dbsi_has( info, DbSI_MADE_V3TOV4 ) ); - dbsi_clr( info, DbSI_HAVE_V3 ); - } - else - { - // Performing an update: Keep the original rpm3 database - // and wait if the rpm4 database gets modified by installing - // or removing packages. Cleanup in modifyDatabase or closeDatabase. - MIL << "Update mode: Cleanup delayed until closeOldDatabase." << endl; - } - } -#warning CHECK: notify root about conversion backup. _root = root_r; _dbPath = dbPath_r; - _dbStateInfo = info; if ( doRebuild_r ) - { - if ( dbsi_has( info, DbSI_HAVE_V4 ) - && ! dbsi_has( info, DbSI_MADE_V4 ) ) - { - rebuildDatabase(); - } - } + rebuildDatabase(); MIL << "Synchronizing keys with zypp keyring" << endl; syncTrustedKeys(); @@ -438,286 +338,6 @@ void RpmDb::initDatabase( Pathname root_r, Pathname dbPath_r, bool doRebuild_r ) /////////////////////////////////////////////////////////////////// // // -// METHOD NAME : RpmDb::internal_initDatabase -// METHOD TYPE : PMError -// -void RpmDb::internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r, - DbStateInfoBits & info_r ) -{ - info_r = DbSI_NO_INIT; - - /////////////////////////////////////////////////////////////////// - // Get info about the desired database dir - /////////////////////////////////////////////////////////////////// - librpmDb::DbDirInfo dbInfo( root_r, dbPath_r ); - - if ( dbInfo.illegalArgs() ) - { - // should not happen (checked in initDatabase) - ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r)); - } - if ( ! dbInfo.usableArgs() ) - { - ERR << "Bad database directory: " << dbInfo.dbDir() << endl; - ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r)); - } - - if ( dbInfo.hasDbV4() ) - { - dbsi_set( info_r, DbSI_HAVE_V4 ); - MIL << "Found rpm4 database in " << dbInfo.dbDir() << endl; - } - else - { - MIL << "Creating new rpm4 database in " << dbInfo.dbDir() << endl; - } - - if ( dbInfo.hasDbV3() ) - { - dbsi_set( info_r, DbSI_HAVE_V3 ); - } - if ( dbInfo.hasDbV3ToV4() ) - { - dbsi_set( info_r, DbSI_HAVE_V3TOV4 ); - } - - DBG << "Initial state: " << info_r << ": " << stringPath( root_r, dbPath_r ); - librpmDb::dumpState( DBG ) << endl; - - /////////////////////////////////////////////////////////////////// - // Access database, create if needed - /////////////////////////////////////////////////////////////////// - - // creates dbdir and empty rpm4 database if not present - librpmDb::dbAccess( root_r, dbPath_r ); - - if ( ! dbInfo.hasDbV4() ) - { - dbInfo.restat(); - if ( dbInfo.hasDbV4() ) - { - dbsi_set( info_r, DbSI_HAVE_V4 | DbSI_MADE_V4 ); - } - } - - DBG << "Access state: " << info_r << ": " << stringPath( root_r, dbPath_r ); - librpmDb::dumpState( DBG ) << endl; - - /////////////////////////////////////////////////////////////////// - // Check whether to convert something. Create backup but do - // not remove anything here - /////////////////////////////////////////////////////////////////// - librpmDb::constPtr dbptr; - librpmDb::dbAccess( dbptr ); - bool dbEmpty = dbptr->empty(); - if ( dbEmpty ) - { - MIL << "Empty rpm4 database " << dbInfo.dbV4() << endl; - } - - if ( dbInfo.hasDbV3() ) - { - MIL << "Found rpm3 database " << dbInfo.dbV3() << endl; - - if ( dbEmpty ) - { - extern void convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r ); - convertV3toV4( dbInfo.dbV3().path(), dbptr ); - - // create a backup copy - int res = filesystem::copy( dbInfo.dbV3().path(), dbInfo.dbV3ToV4().path() ); - if ( res ) - { - WAR << "Backup converted rpm3 database failed: error(" << res << ")" << endl; - } - else - { - dbInfo.restat(); - if ( dbInfo.hasDbV3ToV4() ) - { - MIL << "Backup converted rpm3 database: " << dbInfo.dbV3ToV4() << endl; - dbsi_set( info_r, DbSI_HAVE_V3TOV4 | DbSI_MADE_V3TOV4 ); - } - } - - } - else - { - - WAR << "Non empty rpm3 and rpm4 database found: using rpm4" << endl; - // set DbSI_MODIFIED_V4 as it's not a temporary which can be removed. - dbsi_set( info_r, DbSI_MODIFIED_V4 ); - - } - - DBG << "Convert state: " << info_r << ": " << stringPath( root_r, dbPath_r ); - librpmDb::dumpState( DBG ) << endl; - } - - if ( dbInfo.hasDbV3ToV4() ) - { - MIL << "Rpm3 database backup: " << dbInfo.dbV3ToV4() << endl; - } -} - -/////////////////////////////////////////////////////////////////// -// -// -// METHOD NAME : RpmDb::removeV4 -// METHOD TYPE : void -// -void RpmDb::removeV4( const Pathname & dbdir_r, bool v3backup_r ) -{ - const char * v3backup = "packages.rpm3"; - const char * master = "Packages"; - const char * index[] = - { - "Basenames", - "Conflictname", - "Depends", - "Dirnames", - "Filemd5s", - "Group", - "Installtid", - "Name", - "Providename", - "Provideversion", - "Pubkeys", - "Requirename", - "Requireversion", - "Sha1header", - "Sigmd5", - "Triggername", - // last entry! - NULL - }; - - PathInfo pi( dbdir_r ); - if ( ! pi.isDir() ) - { - ERR << "Can't remove rpm4 database in non directory: " << dbdir_r << endl; - return; - } - - for ( const char ** f = index; *f; ++f ) - { - pi( dbdir_r + *f ); - if ( pi.isFile() ) - { - filesystem::unlink( pi.path() ); - } - } - - pi( dbdir_r + master ); - if ( pi.isFile() ) - { - MIL << "Removing rpm4 database " << pi << endl; - filesystem::unlink( pi.path() ); - } - - if ( v3backup_r ) - { - pi( dbdir_r + v3backup ); - if ( pi.isFile() ) - { - MIL << "Removing converted rpm3 database backup " << pi << endl; - filesystem::unlink( pi.path() ); - } - } -} - -/////////////////////////////////////////////////////////////////// -// -// -// METHOD NAME : RpmDb::removeV3 -// METHOD TYPE : void -// -void RpmDb::removeV3( const Pathname & dbdir_r, bool v3backup_r ) -{ - const char * master = "packages.rpm"; - const char * index[] = - { - "conflictsindex.rpm", - "fileindex.rpm", - "groupindex.rpm", - "nameindex.rpm", - "providesindex.rpm", - "requiredby.rpm", - "triggerindex.rpm", - // last entry! - NULL - }; - - PathInfo pi( dbdir_r ); - if ( ! pi.isDir() ) - { - ERR << "Can't remove rpm3 database in non directory: " << dbdir_r << endl; - return; - } - - for ( const char ** f = index; *f; ++f ) - { - pi( dbdir_r + *f ); - if ( pi.isFile() ) - { - filesystem::unlink( pi.path() ); - } - } - -#warning CHECK: compare vs existing v3 backup. notify root - pi( dbdir_r + master ); - if ( pi.isFile() ) - { - Pathname m( pi.path() ); - if ( v3backup_r ) - { - // backup was already created - filesystem::unlink( m ); - Pathname b( m.extend( "3" ) ); - pi( b ); // stat backup - } - else - { - Pathname b( m.extend( ".deleted" ) ); - pi( b ); - if ( pi.isFile() ) - { - // rempve existing backup - filesystem::unlink( b ); - } - filesystem::rename( m, b ); - pi( b ); // stat backup - } - MIL << "(Re)moved rpm3 database to " << pi << endl; - } -} - -/////////////////////////////////////////////////////////////////// -// -// -// METHOD NAME : RpmDb::modifyDatabase -// METHOD TYPE : void -// -void RpmDb::modifyDatabase() -{ - if ( ! initialized() ) - return; - - // tag database as modified - dbsi_set( _dbStateInfo, DbSI_MODIFIED_V4 ); - - // Move outdated rpm3 database beside. - if ( dbsi_has( _dbStateInfo, DbSI_HAVE_V3 ) ) - { - MIL << "Update mode: Delayed cleanup: state " << _dbStateInfo << endl; - removeV3( _root + _dbPath, dbsi_has( _dbStateInfo, DbSI_MADE_V3TOV4 ) ); - dbsi_clr( _dbStateInfo, DbSI_HAVE_V3 ); - } -} - -/////////////////////////////////////////////////////////////////// -// -// // METHOD NAME : RpmDb::closeDatabase // METHOD TYPE : PMError // @@ -736,28 +356,9 @@ void RpmDb::closeDatabase() librpmDb::blockAccess(); /////////////////////////////////////////////////////////////////// - // Check fate if old version database still present - /////////////////////////////////////////////////////////////////// - if ( dbsi_has( _dbStateInfo, DbSI_HAVE_V3 ) ) - { - MIL << "Update mode: Delayed cleanup: state " << _dbStateInfo << endl; - if ( dbsi_has( _dbStateInfo, DbSI_MODIFIED_V4 ) ) - { - // Move outdated rpm3 database beside. - removeV3( _root + _dbPath, dbsi_has( _dbStateInfo, DbSI_MADE_V3TOV4 ) ); - } - else - { - // Remove unmodified rpm4 database - removeV4( _root + _dbPath, dbsi_has( _dbStateInfo, DbSI_MADE_V3TOV4 ) ); - } - } - - /////////////////////////////////////////////////////////////////// // Uninit /////////////////////////////////////////////////////////////////// _root = _dbPath = Pathname(); - _dbStateInfo = DbSI_NO_INIT; MIL << "closeDatabase: " << *this << endl; } @@ -789,62 +390,73 @@ void RpmDb::rebuildDatabase() void RpmDb::doRebuildDatabase(callback::SendReport & report) { FAILIFNOTINITIALIZED; - MIL << "RpmDb::rebuildDatabase" << *this << endl; - // FIXME Timecount _t( "RpmDb::rebuildDatabase" ); - PathInfo dbMaster( root() + dbPath() + "Packages" ); - PathInfo dbMasterBackup( dbMaster.path().extend( ".y2backup" ) ); - - // run rpm - RpmArgVec opts; - opts.push_back("--rebuilddb"); - opts.push_back("-vv"); - - // don't call modifyDatabase because it would remove the old - // rpm3 database, if the current database is a temporary one. - run_rpm (opts, ExternalProgram::Stderr_To_Stdout); + const Pathname mydbpath { root()/dbPath() }; // the configured path used in reports + { + // For --rebuilddb take care we're using the real db directory + // and not a symlink. Otherwise rpm will rename the symlink and + // replace it with a real directory containing the converted db. + DtorReset guardRoot { _root }; + DtorReset guardDbPath{ _dbPath }; + _root = "/"; + _dbPath = filesystem::expandlink( mydbpath ); - // progress report: watch this file growing - PathInfo newMaster( root() - + dbPath().extend( str::form( "rebuilddb.%d", - process?process->getpid():0) ) - + "Packages" ); + // run rpm + RpmArgVec opts; + opts.push_back("--rebuilddb"); + opts.push_back("-vv"); + run_rpm (opts, ExternalProgram::Stderr_To_Stdout); + } - std::string line; - std::string errmsg; + // generate and report progress + ProgressData tics; + { + ProgressData::value_type hdrTotal = 0; + for ( librpmDb::db_const_iterator it; *it; ++it, ++hdrTotal ) + {;} + tics.range( hdrTotal ); + } + tics.sendTo( [&report,&mydbpath]( const ProgressData & tics_r ) -> bool { + return report->progress( tics_r.reportValue(), mydbpath ); + } ); + tics.toMin(); + std::string line; + std::string errmsg; while ( systemReadLine( line ) ) { - if ( newMaster() ) - { // file is removed at the end of rebuild. - // current size should be upper limit for new db - if ( ! report->progress( (100 * newMaster.size()) / dbMaster.size(), root() + dbPath()) ) + static const std::string debugPrefix { "D:" }; + static const std::string progressPrefix { "D: read h#" }; + static const std::string ignoreSuffix { "digest: OK" }; + + if ( ! str::startsWith( line, debugPrefix ) ) + { + if ( ! str::endsWith( line, ignoreSuffix ) ) { - WAR << "User requested abort." << endl; - systemKill(); - filesystem::recursive_rmdir( newMaster.path().dirname() ); + errmsg += line; + errmsg += '\n'; + WAR << line << endl; } } - - if ( line.compare( 0, 2, "D:" ) ) + else if ( str::startsWith( line, progressPrefix ) ) { - errmsg += line + '\n'; - // report.notify( line ); - WAR << line << endl; + if ( ! tics.incr() ) + { + WAR << "User requested abort." << endl; + systemKill(); + } } } - int rpm_status = systemStatus(); - - if ( rpm_status != 0 ) + if ( systemStatus() != 0 ) { //TranslatorExplanation after semicolon is error message ZYPP_THROW(RpmSubprocessException(std::string(_("RPM failed: ")) + (errmsg.empty() ? error_message: errmsg) ) ); } else { - report->progress( 100, root() + dbPath() ); // 100% + tics.toMax(); } } @@ -1123,8 +735,6 @@ void RpmDb::importPubkey( const PublicKey & pubkey_r ) opts.push_back ( "--allmatches" ); opts.push_back ( "--" ); opts.push_back ( keyName.c_str() ); - // don't call modifyDatabase because it would remove the old - // rpm3 database, if the current database is a temporary one. run_rpm( opts, ExternalProgram::Stderr_To_Stdout ); std::string line; @@ -1149,9 +759,6 @@ void RpmDb::importPubkey( const PublicKey & pubkey_r ) opts.push_back ( "--" ); std::string pubkeypath( pubkey_r.path().asString() ); opts.push_back ( pubkeypath.c_str() ); - - // don't call modifyDatabase because it would remove the old - // rpm3 database, if the current database is a temporary one. run_rpm( opts, ExternalProgram::Stderr_To_Stdout ); std::string line; @@ -1219,9 +826,6 @@ void RpmDb::removePubkey( const PublicKey & pubkey_r ) opts.push_back ( "-e" ); opts.push_back ( "--" ); opts.push_back ( rpm_name.c_str() ); - - // don't call modifyDatabase because it would remove the old - // rpm3 database, if the current database is a temporary one. run_rpm( opts, ExternalProgram::Stderr_To_Stdout ); std::string line; @@ -2061,8 +1665,6 @@ void RpmDb::doInstallPackage( const Pathname & filename, RpmInstFlags flags, cal // rpm requires additional quoting of special chars: std::string quotedFilename( rpmQuoteFilename( workaroundRpmPwdBug( filename ) ) ); opts.push_back ( quotedFilename.c_str() ); - - modifyDatabase(); // BEFORE run_rpm run_rpm( opts, ExternalProgram::Stderr_To_Stdout ); std::string line; @@ -2232,8 +1834,6 @@ void RpmDb::doRemovePackage( const std::string & name_r, RpmInstFlags flags, cal opts.push_back("--"); opts.push_back(name_r.c_str()); - - modifyDatabase(); // BEFORE run_rpm run_rpm (opts, ExternalProgram::Stderr_To_Stdout); std::string line; diff --git a/zypp/target/rpm/RpmDb.h b/zypp/target/rpm/RpmDb.h index a5b8a8a..b5a1e3f 100644 --- a/zypp/target/rpm/RpmDb.h +++ b/zypp/target/rpm/RpmDb.h @@ -59,36 +59,12 @@ public: // /////////////////////////////////////////////////////////////////// private: - +#if LEGACY(1712) enum DbStateInfoBits { - DbSI_NO_INIT = 0x0000, - DbSI_HAVE_V4 = 0x0001, - DbSI_MADE_V4 = 0x0002, - DbSI_MODIFIED_V4 = 0x0004, - DbSI_HAVE_V3 = 0x0008, - DbSI_HAVE_V3TOV4 = 0x0010, - DbSI_MADE_V3TOV4 = 0x0020 + DbSI_NO_INIT = 0x0000 }; - - friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj ); - - void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const - { - val_r = (DbStateInfoBits)(val_r | bits_r); - } - void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const - { - val_r = (DbStateInfoBits)(val_r & ~bits_r); - } - bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const - { - return( (val_r & bits_r) == bits_r ); - } - - /** - * Internal state info - **/ DbStateInfoBits _dbStateInfo; +#endif /** * Root directory for all operations. @@ -100,33 +76,6 @@ private: **/ Pathname _dbPath; - /** - * Internal helper for @ref initDatabase. - * - * \throws RpmException - * - **/ - void internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r, - DbStateInfoBits & info_r ); - - /** - * Remove the rpm4 database in dbdir_r and optionally any backup created - * on conversion. - **/ - static void removeV4( const Pathname & dbdir_r, bool v3backup_r ); - - /** - * Remove the rpm3 database in dbdir_r. Create a backup copy named - * packages.rpm3 if it does not already exist. - **/ - static void removeV3( const Pathname & dbdir_r, bool v3backup_r ); - - /** - * Called before the database is modified by installPackage/removePackage. - * Invalidates Packages list and moves away any old database. - **/ - void modifyDatabase(); - public: /** @@ -141,11 +90,6 @@ public: ~RpmDb(); /** - * timestamp of the rpm database (last modification) - */ - Date timestamp() const; - - /** * @return Root directory for all operations (empty if not initialized). **/ const Pathname & root() const @@ -170,33 +114,20 @@ public: } /** - * Prepare access to the rpm database. Optional arguments may denote the - * root directory for all operations and the directory (below root) that - * contains the rpmdb (usg. you won't need to set this). + * Prepare access to the rpm database at \c/var/lib/rpm. * - * On empty Pathnames the default is used: - *
-   *     root:   /
-   *     dbPath: /var/lib/rpm
-   * 
+ * An optional argument denotes the root directory for all operations. If + * an empty Pathname is given the default (\c/) is used. * * Calling initDatabase a second time with different arguments will return * an error but leave the database in it's original state. * - * Converting an old batabase is done if necessary. On update: The converted - * database will be removed by @ref closeDatabase, if it was not modified - * (no packages were installed or deleted). Otherwise the new database - * is kept, and the old one is removed. - * - * If the database alredy exists and \c doRebuild_r is true, \ref rebuildDatabase - * is called. + * If the database already exists and \c doRebuild_r is true, + * \ref rebuildDatabase is called. * * \throws RpmException - * **/ - void initDatabase( Pathname root_r = Pathname(), - Pathname dbPath_r = Pathname(), - bool doRebuild_r = false ); + void initDatabase( Pathname root_r = Pathname(), bool doRebuild_r = false ); /** * Block further access to the rpm database and go back to uninitialized @@ -399,9 +330,10 @@ private: /** create package backups? */ bool _packagebackups; +#if LEGACY(1712) /** whether <_root>/ was already created */ bool _warndirexists; - +#endif /** * handle rpm messages like "/etc/testrc saved as /etc/testrc.rpmorig" * diff --git a/zypp/target/rpm/librpmDb.cc b/zypp/target/rpm/librpmDb.cc index edf6ff5..daf6cef 100644 --- a/zypp/target/rpm/librpmDb.cc +++ b/zypp/target/rpm/librpmDb.cc @@ -65,28 +65,7 @@ public: _ts = ::rpmtsCreate(); ::rpmtsSetRootDir( _ts, _root.c_str() ); - // check whether to create a new db - PathInfo master( _root + _dbPath + "Packages" ); - if ( ! master.isFile() ) - { - // init database - if ( filesystem::assert_dir(_root + _dbPath) != 0 ) - { - ERR << "Could not create dbpath " << (_root + _dbPath).asString() << endl; - _error = shared_ptr(new RpmInitException(_root, _dbPath)); - ZYPP_THROW(*_error); - } - int res = ::rpmtsInitDB( _ts, 0644 ); - if ( res ) - { - ERR << "rpmdbInit error(" << res << "): " << *this << endl; - _error = shared_ptr(new RpmInitException(_root, _dbPath)); - rpmtsFree(_ts); - ZYPP_THROW(*_error); - } - } - - // open database + // open database (creates a missing one on the fly) int res = ::rpmtsOpenDB( _ts, (readonly_r ? O_RDONLY : O_RDWR )); if ( res ) { @@ -118,7 +97,12 @@ public: /////////////////////////////////////////////////////////////////// Pathname librpmDb::_defaultRoot ( "/" ); -Pathname librpmDb::_defaultDbPath( "/var/lib/rpm" ); +// NOTE: Former variable, but now locked to "/var/lib/rpm". +// A custom dbPath is not actually needed and would only work +// reliably if libsolv also supports it. +// The protected librpmDb ctor would allow to build a db_const_iterator +// to access (ro) a database at a custom location. +const Pathname librpmDb::_defaultDbPath( "/var/lib/rpm" ); librpmDb::constPtr librpmDb::_defaultDb; bool librpmDb::_dbBlocked ( true ); @@ -179,14 +163,8 @@ std::string librpmDb::expand( const std::string & macro_r ) // METHOD NAME : librpmDb::newLibrpmDb // METHOD TYPE : librpmDb * // -librpmDb * librpmDb::newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r ) +librpmDb * librpmDb::newLibrpmDb() { - // check arguments - if ( ! (root_r.absolute() && dbPath_r.absolute()) ) - { - ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r)); - } - // initialize librpm if ( ! globalInit() ) { @@ -197,7 +175,7 @@ librpmDb * librpmDb::newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool reado librpmDb * ret = 0; try { - ret = new librpmDb( root_r, dbPath_r, readonly_r ); + ret = new librpmDb( _defaultRoot, _defaultDbPath, /*readonly*/true ); } catch (const RpmException & excpt_r) { @@ -215,28 +193,30 @@ librpmDb * librpmDb::newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool reado // METHOD NAME : librpmDb::dbAccess // METHOD TYPE : PMError // -void librpmDb::dbAccess( const Pathname & root_r, const Pathname & dbPath_r ) +void librpmDb::dbAccess( const Pathname & root_r ) { - // check arguments - if ( ! (root_r.absolute() && dbPath_r.absolute()) ) - { - ZYPP_THROW(RpmInvalidRootException(root_r, dbPath_r)); - } - if ( _defaultDb ) { // already accessing a database: switching is not allowed. - if ( _defaultRoot == root_r && _defaultDbPath == dbPath_r ) + if ( _defaultRoot == root_r ) return; else - { - ZYPP_THROW(RpmDbAlreadyOpenException(_defaultRoot, _defaultDbPath, root_r, dbPath_r)); - } + ZYPP_THROW(RpmDbAlreadyOpenException(_defaultRoot, _defaultDbPath, root_r, _defaultDbPath)); } // got no database: we could switch to a new one (even if blocked!) + + if ( root_r.empty() || ! root_r.absolute() ) + ZYPP_THROW(RpmInvalidRootException(root_r, _defaultDbPath)); + + PathInfo pi { root_r / _defaultDbPath }; + if ( pi.isExist() && ! pi.isDir() ) { + RpmInvalidRootException excpt { root_r, _defaultDbPath }; + excpt.addHistory( str::Str() << pi ); + ZYPP_THROW(excpt); + } + _defaultRoot = root_r; - _defaultDbPath = dbPath_r; MIL << "Set new database location: " << stringPath( _defaultRoot, _defaultDbPath ) << endl; return dbAccess(); @@ -258,7 +238,7 @@ void librpmDb::dbAccess() if ( !_defaultDb ) { // get access - _defaultDb = newLibrpmDb( _defaultRoot, _defaultDbPath, /*readonly*/true ); + _defaultDb = newLibrpmDb(); } } @@ -270,16 +250,8 @@ void librpmDb::dbAccess() // void librpmDb::dbAccess( librpmDb::constPtr & ptr_r ) { - try - { - dbAccess(); - } - catch (const RpmException & excpt_r) - { - ZYPP_CAUGHT(excpt_r); - ptr_r = 0; - ZYPP_RETHROW(excpt_r); - } + ptr_r = nullptr; + dbAccess(); ptr_r = _defaultDb; } @@ -494,75 +466,6 @@ ostream & librpmDb::dumpOn( ostream & str ) const /////////////////////////////////////////////////////////////////// // -// CLASS NAME : librpmDb::DbDirInfo -// -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// -// -// METHOD NAME : librpmDb::DbDirInfo::DbDirInfo -// METHOD TYPE : Constructor -// -librpmDb::DbDirInfo::DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r ) - : _root( root_r ) - , _dbPath( dbPath_r ) -{ - // check and adjust arguments - if ( ! (root_r.absolute() && dbPath_r.absolute()) ) - { - ERR << "Relative path for root(" << _root << ") or dbPath(" << _dbPath << ")" << endl; - } - else - { - _dbDir ( _root + _dbPath ); - _dbV4 ( _dbDir.path() + "Packages" ); - _dbV3 ( _dbDir.path() + "packages.rpm" ); - _dbV3ToV4( _dbDir.path() + "packages.rpm3" ); - DBG << *this << endl; - } -} - -/////////////////////////////////////////////////////////////////// -// -// -// METHOD NAME : librpmDb::DbDirInfo::update -// METHOD TYPE : void -// -void librpmDb::DbDirInfo::restat() -{ - _dbDir(); - _dbV4(); - _dbV3(); - _dbV3ToV4(); - DBG << *this << endl; -} - -/****************************************************************** -** -** -** FUNCTION NAME : operator<< -** FUNCTION TYPE : std::ostream & -*/ -std::ostream & operator<<( std::ostream & str, const librpmDb::DbDirInfo & obj ) -{ - if ( obj.illegalArgs() ) - { - str << "ILLEGAL: '(" << obj.root() << ")" << obj.dbPath() << "'"; - } - else - { - str << "'(" << obj.root() << ")" << obj.dbPath() << "':" << endl; - str << " Dir: " << obj._dbDir << endl; - str << " V4: " << obj._dbV4 << endl; - str << " V3: " << obj._dbV3 << endl; - str << " V3ToV4: " << obj._dbV3ToV4; - } - return str; -} - -/////////////////////////////////////////////////////////////////// -// // CLASS NAME : librpmDb::db_const_iterator::D /** * diff --git a/zypp/target/rpm/librpmDb.cv3.cc b/zypp/target/rpm/librpmDb.cv3.cc deleted file mode 100644 index a3442cb..0000000 --- a/zypp/target/rpm/librpmDb.cv3.cc +++ /dev/null @@ -1,61 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/target/rpm/librpmDb.cv3.cc - * - */ -#include - -#include "zypp/base/Logger.h" - -#include "zypp/target/rpm/librpmDb.h" -#include "zypp/target/rpm/RpmCallbacks.h" -#include "zypp/ZYppCallbacks.h" - -using namespace std; - -#undef Y2LOG -#define Y2LOG "librpmDb" - -namespace zypp -{ -namespace target -{ -namespace rpm -{ -/****************************************************************** -* -* -* FUNCTION NAME : convertV3toV4 -* -* \throws RpmException -* -*/ -void convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r ) -{ - // report - callback::SendReport report; - report->start(v3db_r); - try - { - // Does no longer work with rpm 4.9. - // internal_convertV3toV4( v3db_r, v4db_r, report ); - INT << "Unsupported: Convert rpm3 database to rpm4" << endl; - ZYPP_THROW(RpmDbOpenException(Pathname("/"), v3db_r)); - } - catch (RpmException & excpt_r) - { - report->finish(v3db_r, ConvertDBReport::FAILED,excpt_r.asUserString()); - ZYPP_RETHROW(excpt_r); - } - report->finish(v3db_r, ConvertDBReport::NO_ERROR, ""); -} - -} // namespace rpm -} // namespace target -} // namespace zypp diff --git a/zypp/target/rpm/librpmDb.h b/zypp/target/rpm/librpmDb.h index 50dfc81..8c0e3c0 100644 --- a/zypp/target/rpm/librpmDb.h +++ b/zypp/target/rpm/librpmDb.h @@ -71,7 +71,7 @@ private: * Current directory (below root) that contains the rpmdb. * (initialy /var/lib/rpm) **/ - static Pathname _defaultDbPath; + static const Pathname _defaultDbPath; /** * Current rpmdb handle. @@ -90,7 +90,7 @@ private: * \throws RpmException * **/ - static librpmDb * newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r ); + static librpmDb * newLibrpmDb(); /** * Access the database at the current default location. If necessary @@ -161,7 +161,7 @@ public: * \throws RpmException * **/ - static void dbAccess( const Pathname & root_r, const Pathname & dbPath_r ); + static void dbAccess( const Pathname & root_r ); /** * Same as &ref dbAccess(), but returns the database handle if @@ -225,12 +225,6 @@ public: public: /** - * Collect info about what kind of rpmdb seems to be present by - * looking at paths and filenames. - **/ - class DbDirInfo; - - /** * Subclass to retrieve database content. **/ class db_const_iterator; @@ -319,168 +313,6 @@ public: /////////////////////////////////////////////////////////////////// // -// CLASS NAME : librpmDb::DbDirInfo -/** - * Collect info about what kind of rpmdb seems to be present by - * looking at paths and filenames. - **/ -class librpmDb::DbDirInfo -{ - friend std::ostream & operator<<( std::ostream & str, const DbDirInfo & obj ); - -private: - - /** - * Root directory for all operations. - **/ - Pathname _root; - - /** - * Directory that contains the rpmdb. - **/ - Pathname _dbPath; - - /** - * database directory (unset on illegal constructor arguments) - **/ - PathInfo _dbDir; - - /** - * rpmV4 database (_dbDir/Packages) - **/ - PathInfo _dbV4; - - /** - * rpmV3 database (_dbDir/packages.rpm) - **/ - PathInfo _dbV3; - - /** - * rpmV3 database backup created on conversion to rpmV4 (_dbDir/packages.rpm3) - **/ - PathInfo _dbV3ToV4; - -public: - - /** - * For Constructor arguments see @ref accessPath. On illegal - * arguments @ref _dbDir is unset. - **/ - DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r ); - -public: - - /** - * Root directory for all operations. - **/ - const Pathname & root() const - { - return _root; - } - - /** - * Directory that contains the rpmdb. - **/ - const Pathname & dbPath() const - { - return _dbPath; - } - - /** - * database directory (unset on illegal constructor arguments) - **/ - const PathInfo & dbDir() const - { - return _dbDir; - } - - /** - * rpmV4 database (_dbDir/Packages) - **/ - const PathInfo & dbV4() const - { - return _dbV4; - } - - /** - * rpmV3 database (_dbDir/packages.rpm) - **/ - const PathInfo & dbV3() const - { - return _dbV3; - } - - /** - * rpmV3 database backup created on conversion to rpmV4 (_dbDir/packages.rpm3) - **/ - const PathInfo & dbV3ToV4() const - { - return _dbV3ToV4; - } - -public: - - /** - * Restat all paths - **/ - void restat(); - -public: - - /** - * Whether constructor arguments were illegal. - **/ - bool illegalArgs() const - { - return _dbDir.path().empty(); - } - - /** - * Whether constructor arguments were llegal and dbDir either - * is a directory or may be created (path does not exist). - **/ - bool usableArgs() const - { - return _dbDir.isDir() || ! ( _dbDir.path().empty() || _dbDir.isExist() ); - } - - /** - * Whether dbDir directory exists. - **/ - bool hasDbDir() const - { - return _dbDir.isDir(); - } - - /** - * Whether dbV4 file exists. - **/ - bool hasDbV4() const - { - return _dbV4.isFile(); - } - - /** - * Whether dbV3 file exists. - **/ - bool hasDbV3() const - { - return _dbV3.isFile(); - } - - /** - * Whether dbV3ToV4 file exists. - **/ - bool hasDbV3ToV4() const - { - return _dbV3ToV4.isFile(); - } -}; - -/////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -// // CLASS NAME : librpmDb::db_const_iterator /** * @short Subclass to retrieve database content.