-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce download-retry and download-retry-wait settings in ZConfig #400
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<class Tp> | ||
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<class Tp> | ||
struct DefaultOption : public Option<Tp> | ||
{ | ||
typedef Tp value_type; | ||
typedef Option<Tp> option_type; | ||
|
||
explicit DefaultOption( value_type initial_r ) | ||
: Option<Tp>( 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,28 +13,40 @@ | |
#include "mediaconfig.h" | ||
#include <zypp-core/Pathname.h> | ||
#include <zypp-core/base/String.h> | ||
#include <zypp-core/base/private/configoption_p.h> | ||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you introduce new limit's, then it must be documented. The accessor in ZConfig.h schould mention it. If it is also exposed in zypp.conf we should think twice whether we need to introduce a restriction (an break existing behavior). If so, it must be documented in the zypp.conf template we install in the system and the zypper man page must be checked, whether it mentions the value. And we need a good explanation why?. |
||
|
||
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<long> download_max_silent_tries {1}; | ||
DefaultOption<long> download_retry_wait_time {0}; | ||
int download_transfer_timeout = 180; | ||
}; | ||
|
||
MediaConfig::MediaConfig() : d_ptr( new MediaConfigPrivate() ) | ||
|
@@ -70,14 +82,21 @@ 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" ) { | ||
str::strtonum(value, d->download_transfer_timeout); | ||
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) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ripping out the
struct Option
s, placing them in a new header file and adding the header file to CMake schoul go into a separate commit. That's pure cleanup and not related to any fix.