config/Param: overload GetPath() throwing exception

This commit is contained in:
Max Kellermann 2016-10-28 11:53:21 +02:00
parent 7a3415166e
commit 9b5bae049c
2 changed files with 23 additions and 0 deletions

View File

@ -23,6 +23,8 @@
#include "fs/AllocatedPath.hxx"
#include "util/Error.hxx"
#include <stdexcept>
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;
}

View File

@ -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