diff --git a/src/StateFileConfig.cxx b/src/StateFileConfig.cxx index ac54052b1..22788d86e 100644 --- a/src/StateFileConfig.cxx +++ b/src/StateFileConfig.cxx @@ -10,7 +10,8 @@ StateFileConfig::StateFileConfig(const ConfigData &config) :path(config.GetPath(ConfigOption::STATE_FILE)), - interval(config.GetUnsigned(ConfigOption::STATE_FILE_INTERVAL, + interval(config.GetDuration(ConfigOption::STATE_FILE_INTERVAL, + std::chrono::seconds{1}, DEFAULT_INTERVAL)), restore_paused(config.GetBool(ConfigOption::RESTORE_PAUSED, false)) { diff --git a/src/config/Data.cxx b/src/config/Data.cxx index 202f2b674..72da3ba81 100644 --- a/src/config/Data.cxx +++ b/src/config/Data.cxx @@ -86,32 +86,17 @@ ConfigData::GetPositive(ConfigOption option, unsigned default_value) const } std::chrono::steady_clock::duration -ConfigData::GetUnsigned(ConfigOption option, +ConfigData::GetDuration(ConfigOption option, + std::chrono::steady_clock::duration min_value, std::chrono::steady_clock::duration default_value) const { - return With(option, [default_value](const char *s){ + return With(option, [min_value, default_value](const char *s){ if (s == nullptr) return default_value; auto value = ParseDuration(s); - if (value < std::chrono::steady_clock::duration{}) - throw std::runtime_error("Value must not be negative"); - - return value; - }); -} - -std::chrono::steady_clock::duration -ConfigData::GetPositive(ConfigOption option, - std::chrono::steady_clock::duration default_value) const -{ - return With(option, [default_value](const char *s){ - if (s == nullptr) - return default_value; - - auto value = ParseDuration(s); - if (value <= std::chrono::steady_clock::duration{}) - throw std::runtime_error("Value must be positive"); + if (value < min_value) + throw std::runtime_error{"Value is too small"}; return value; }); diff --git a/src/config/Data.hxx b/src/config/Data.hxx index 7718d71f1..cac7f3f4e 100644 --- a/src/config/Data.hxx +++ b/src/config/Data.hxx @@ -60,15 +60,12 @@ struct ConfigData { unsigned GetUnsigned(ConfigOption option, unsigned default_value) const; - std::chrono::steady_clock::duration - GetUnsigned(ConfigOption option, - std::chrono::steady_clock::duration default_value) const; - unsigned GetPositive(ConfigOption option, unsigned default_value) const; std::chrono::steady_clock::duration - GetPositive(ConfigOption option, + GetDuration(ConfigOption option, + std::chrono::steady_clock::duration min_value, std::chrono::steady_clock::duration default_value) const; bool GetBool(ConfigOption option, bool default_value) const;