Commit 9b5bae04 authored by Max Kellermann's avatar Max Kellermann

config/Param: overload GetPath() throwing exception

parent 7a341516
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include <stdexcept>
ConfigParam::ConfigParam(const char *_value, int _line) ConfigParam::ConfigParam(const char *_value, int _line)
:next(nullptr), value(_value), line(_line), used(false) {} :next(nullptr), value(_value), line(_line), used(false) {}
...@@ -41,3 +43,15 @@ ConfigParam::GetPath(Error &error) const ...@@ -41,3 +43,15 @@ ConfigParam::GetPath(Error &error) const
return path; 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;
}
...@@ -72,6 +72,15 @@ struct ConfigParam { ...@@ -72,6 +72,15 @@ struct ConfigParam {
* AllocatedPath::Null() and sets the error. * AllocatedPath::Null() and sets the error.
*/ */
AllocatedPath GetPath(Error &error) const; 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 #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment