From 9b5bae049c70a7e35c00a75de6cd88850a4ce9b3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 28 Oct 2016 11:53:21 +0200 Subject: [PATCH] config/Param: overload GetPath() throwing exception --- src/config/Param.cxx | 14 ++++++++++++++ src/config/Param.hxx | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/src/config/Param.cxx b/src/config/Param.cxx index 46e9ce024..a3288c946 100644 --- a/src/config/Param.cxx +++ b/src/config/Param.cxx @@ -23,6 +23,8 @@ #include "fs/AllocatedPath.hxx" #include "util/Error.hxx" +#include + ConfigParam::ConfigParam(const char *_value, int _line) :next(nullptr), value(_value), line(_line), used(false) {} @@ -41,3 +43,15 @@ ConfigParam::GetPath(Error &error) const return path; } + +AllocatedPath +ConfigParam::GetPath() const +{ + Error error; + auto path = ParsePath(value.c_str(), error); + if (gcc_unlikely(path.IsNull())) + throw std::runtime_error(error.GetMessage()); + + return path; + +} diff --git a/src/config/Param.hxx b/src/config/Param.hxx index c009ea0a4..a1a5fccd2 100644 --- a/src/config/Param.hxx +++ b/src/config/Param.hxx @@ -72,6 +72,15 @@ struct ConfigParam { * AllocatedPath::Null() and sets the error. */ AllocatedPath GetPath(Error &error) const; + + /** + * Parse the value as a path. If there is a tilde prefix, it + * is expanded. + * + * Throws #std::runtime_error on error. + */ + gcc_pure + AllocatedPath GetPath() const; }; #endif