diff --git a/zypp-core/CMakeLists.txt b/zypp-core/CMakeLists.txt index 4fae805138..a568a87e71 100644 --- a/zypp-core/CMakeLists.txt +++ b/zypp-core/CMakeLists.txt @@ -37,6 +37,10 @@ SET( zypp_toplevel_SRCS ) INSTALL( FILES ${zypp_toplevel_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/zypp-core" ) +SET( zypp_base_private_HEADERS + base/private/configoption_p.h +) + SET( zypp_base_HEADERS base/DefaultIntegral base/defaultintegral.h @@ -333,6 +337,7 @@ SET ( zypp_HEADERS ${zypp_toplevel_headers} ${zyppng_async_HEADERS} ${zypp_base_HEADERS} + ${zypp_base_private_HEADERS} ${zypp_fs_HEADERS} ${zypp_ui_HEADERS} ${zypp_url_HEADERS} diff --git a/zypp-core/base/private/configoption_p.h b/zypp-core/base/private/configoption_p.h new file mode 100644 index 0000000000..c90d9395bb --- /dev/null +++ b/zypp-core/base/private/configoption_p.h @@ -0,0 +1,74 @@ +#ifndef ZYPP_CORE_BASE_PRIVATE_CONFIGOPTION_P_H +#define ZYPP_CORE_BASE_PRIVATE_CONFIGOPTION_P_H + +namespace zypp +{ + + /** Mutable option. */ + template + struct Option + { + typedef Tp value_type; + + /** No default ctor, explicit initialisation! */ + Option( value_type initial_r ) + : _val( std::move(initial_r) ) + {} + + Option & operator=( value_type newval_r ) + { set( std::move(newval_r) ); return *this; } + + /** Get the value. */ + const value_type & get() const + { return _val; } + + /** Autoconversion to value_type. */ + operator const value_type &() const + { return _val; } + + /** Set a new value. */ + void set( value_type newval_r ) + { _val = std::move(newval_r); } + + private: + value_type _val; + }; + + /** Mutable option with initial value also remembering a config value. */ + template + struct DefaultOption : public Option + { + typedef Tp value_type; + typedef Option option_type; + + explicit DefaultOption( value_type initial_r ) + : Option( initial_r ) + , _default( std::move(initial_r) ) + {} + + DefaultOption & operator=( value_type newval_r ) + { this->set( std::move(newval_r) ); return *this; } + + /** Reset value to the current default. */ + void restoreToDefault() + { this->set( _default.get() ); } + + /** Reset value to a new default. */ + void restoreToDefault( value_type newval_r ) + { setDefault( std::move(newval_r) ); restoreToDefault(); } + + /** Get the current default value. */ + const value_type & getDefault() const + { return _default.get(); } + + /** Set a new default value. */ + void setDefault( value_type newval_r ) + { _default.set( std::move(newval_r) ); } + + private: + option_type _default; + }; + +} + +#endif // ZYPP_CORE_BASE_PRIVATE_CONFIGOPTION_P_H diff --git a/zypp-media/mediaconfig.cc b/zypp-media/mediaconfig.cc index bf0c473d29..1a5779607b 100644 --- a/zypp-media/mediaconfig.cc +++ b/zypp-media/mediaconfig.cc @@ -13,28 +13,40 @@ #include "mediaconfig.h" #include #include +#include namespace zypp { class MediaConfigPrivate { public: - MediaConfigPrivate() - : download_max_concurrent_connections( 5 ) - , download_min_download_speed ( 0 ) - , download_max_download_speed ( 0 ) - , download_max_silent_tries ( 5 ) - , download_transfer_timeout ( 180 ) - { } + MediaConfigPrivate(){ } + + + void set_download_retry_wait_time( long val, bool overrideDefault = false ) { + if ( val < 0 ) val = 0; + else if ( val > 3600 ) val = 3600; + if ( overrideDefault ) download_retry_wait_time.setDefault( val ); + else download_retry_wait_time = val; + } + + void set_download_max_silent_tries( long val, bool overrideDefault = false ) { + if ( val < 0 ) val = 0; + else if ( val > 10 ) val = 10; + + if ( overrideDefault ) download_max_silent_tries.setDefault( val ); + else download_max_silent_tries = val; + } Pathname credentials_global_dir_path; Pathname credentials_global_file_path; - int download_max_concurrent_connections; - int download_min_download_speed; - int download_max_download_speed; - int download_max_silent_tries; - int download_transfer_timeout; + int download_max_concurrent_connections = 5; + int download_min_download_speed = 0; + int download_max_download_speed = 0; + DefaultOption download_max_silent_tries {1}; + DefaultOption download_retry_wait_time {0}; + int download_transfer_timeout = 180; }; MediaConfig::MediaConfig() : d_ptr( new MediaConfigPrivate() ) @@ -70,7 +82,9 @@ namespace zypp { return true; } else if ( entry == "download.max_silent_tries" ) { - str::strtonum(value, d->download_max_silent_tries); + long val; + str::strtonum(value, val); + d->set_download_max_silent_tries( val, true ); return true; } else if ( entry == "download.transfer_timeout" ) { @@ -78,6 +92,11 @@ namespace zypp { if ( d->download_transfer_timeout < 0 ) d->download_transfer_timeout = 0; else if ( d->download_transfer_timeout > 3600 ) d->download_transfer_timeout = 3600; return true; + } else if ( entry == "download.retry_wait_time" ) { + long val; + str::strtonum(value, val); + d->set_download_retry_wait_time( val, true ); + return true; } } return false; @@ -109,10 +128,35 @@ namespace zypp { long MediaConfig::download_max_silent_tries() const { return d_func()->download_max_silent_tries; } + void MediaConfig::set_download_max_silent_tries( long val ) + { + Z_D(); + d->set_download_max_silent_tries( val ); + } + + void MediaConfig::reset_download_max_silent_tries () + { + Z_D(); + d->download_max_silent_tries.restoreToDefault(); + } + + long MediaConfig::download_retry_wait_time() const + { return d_func()->download_retry_wait_time; } + + void MediaConfig::set_download_retry_wait_time ( long val ) + { + Z_D(); + d->set_download_retry_wait_time( val ); + } + + void MediaConfig::reset_download_retry_wait_time () + { + Z_D(); + d->download_retry_wait_time.restoreToDefault(); + } + long MediaConfig::download_transfer_timeout() const { return d_func()->download_transfer_timeout; } ZYPP_IMPL_PRIVATE(MediaConfig) } - - diff --git a/zypp-media/mediaconfig.h b/zypp-media/mediaconfig.h index ed8bc90ed4..14a2c67080 100644 --- a/zypp-media/mediaconfig.h +++ b/zypp-media/mediaconfig.h @@ -80,6 +80,25 @@ namespace zypp { */ long download_max_silent_tries() const; + void set_download_max_silent_tries( long val ); + + /*! + * Reset the download max tries to the configured default + */ + void reset_download_max_silent_tries (); + + /*! + * How long should zypp wait before attempting a retry of a failed download + */ + long download_retry_wait_time() const; + + void set_download_retry_wait_time ( long val ); + + /*! + * Reset the download retry time to the configured default + */ + void reset_download_retry_wait_time (); + /*! * Maximum time in seconds that you allow a transfer operation to take. */ diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc index 5fd3265822..3fa8f04416 100644 --- a/zypp/ZConfig.cc +++ b/zypp/ZConfig.cc @@ -25,6 +25,7 @@ extern "C" #include #include #include +#include #include #include @@ -238,71 +239,6 @@ namespace zypp } // namespace zypp /////////////////////////////////////////////////////////////////// - /** Mutable option. */ - template - struct Option - { - typedef Tp value_type; - - /** No default ctor, explicit initialisation! */ - Option( value_type initial_r ) - : _val( std::move(initial_r) ) - {} - - Option & operator=( value_type newval_r ) - { set( std::move(newval_r) ); return *this; } - - /** Get the value. */ - const value_type & get() const - { return _val; } - - /** Autoconversion to value_type. */ - operator const value_type &() const - { return _val; } - - /** Set a new value. */ - void set( value_type newval_r ) - { _val = std::move(newval_r); } - - private: - value_type _val; - }; - - /** Mutable option with initial value also remembering a config value. */ - template - struct DefaultOption : public Option - { - typedef Tp value_type; - typedef Option option_type; - - explicit DefaultOption( value_type initial_r ) - : Option( initial_r ) - , _default( std::move(initial_r) ) - {} - - DefaultOption & operator=( value_type newval_r ) - { this->set( std::move(newval_r) ); return *this; } - - /** Reset value to the current default. */ - void restoreToDefault() - { this->set( _default.get() ); } - - /** Reset value to a new default. */ - void restoreToDefault( value_type newval_r ) - { setDefault( std::move(newval_r) ); restoreToDefault(); } - - /** Get the current default value. */ - const value_type & getDefault() const - { return _default.get(); } - - /** Set a new default value. */ - void setDefault( value_type newval_r ) - { _default.set( std::move(newval_r) ); } - - private: - option_type _default; - }; - /////////////////////////////////////////////////////////////////// // // CLASS NAME : ZConfig::Impl @@ -1086,9 +1022,24 @@ namespace zypp long ZConfig::download_max_silent_tries() const { return _pimpl->_mediaConf.download_max_silent_tries(); } + void ZConfig::set_download_max_silent_tries( long val ) + { _pimpl->_mediaConf.set_download_max_silent_tries(val); } + + void ZConfig::reset_download_max_silent_tries( ) + { _pimpl->_mediaConf.reset_download_max_silent_tries(); } + long ZConfig::download_transfer_timeout() const { return _pimpl->_mediaConf.download_transfer_timeout(); } + long ZConfig::download_retry_wait_time() const + { return _pimpl->_mediaConf.download_retry_wait_time(); } + + void ZConfig::set_download_retry_wait_time ( long val ) + { _pimpl->_mediaConf.set_download_retry_wait_time(val); } + + void ZConfig::reset_download_retry_wait_time () + { _pimpl->_mediaConf.reset_download_retry_wait_time(); } + Pathname ZConfig::download_mediaMountdir() const { return _pimpl->download_mediaMountdir; } void ZConfig::set_download_mediaMountdir( Pathname newval_r ) { _pimpl->download_mediaMountdir.set( std::move(newval_r) ); } void ZConfig::set_default_download_mediaMountdir() { _pimpl->download_mediaMountdir.restoreToDefault(); } diff --git a/zypp/ZConfig.h b/zypp/ZConfig.h index f26f50066a..10ecdc3be1 100644 --- a/zypp/ZConfig.h +++ b/zypp/ZConfig.h @@ -284,6 +284,17 @@ namespace zypp */ long download_max_silent_tries() const; + void set_download_max_silent_tries( long val ); + void reset_download_max_silent_tries( ); + + /*! + * How long should zypp wait before attempting a retry of a failed download + */ + long download_retry_wait_time() const; + + void set_download_retry_wait_time ( long val ); + void reset_download_retry_wait_time (); + /** * Maximum time in seconds that you allow a transfer operation to take. */