0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 20:28:52 +02:00

ircd::fs: Add ability to change basepath values at runtime.

This commit is contained in:
Jason Volk 2019-06-06 17:11:54 -07:00
parent 38bfb56661
commit 32e94931a7
2 changed files with 22 additions and 1 deletions

View file

@ -62,12 +62,15 @@ namespace ircd::fs
/// A compile-time installation base-path. We have several of these in an /// A compile-time installation base-path. We have several of these in an
/// internal array accessible with get(enum base) or make_path(enum base). /// internal array accessible with get(enum base) or make_path(enum base).
/// These can still be modified at runtime by setting a new platform-dependent
/// string with set(enum base); do so with care.
struct ircd::fs::basepath struct ircd::fs::basepath
{ {
string_view name; string_view name;
string_view path; string_view path;
static const basepath &get(const base &) noexcept; static const basepath &get(const base &) noexcept;
static string_view set(const base &, const string_view &); // (returns old value)
}; };
/// Index of default paths. Must be aligned with the internal array in fs.cc. /// Index of default paths. Must be aligned with the internal array in fs.cc.

View file

@ -2225,7 +2225,7 @@ catch(const filesystem::filesystem_error &e)
namespace ircd::fs namespace ircd::fs
{ {
extern const std::array<basepath, num_of<base>()> basepaths; extern std::array<basepath, num_of<base>()> basepaths;
} }
decltype(ircd::fs::basepaths) decltype(ircd::fs::basepaths)
@ -2240,6 +2240,24 @@ ircd::fs::basepaths
{ "module directory", RB_MODULE_DIR }, { "module directory", RB_MODULE_DIR },
}}; }};
ircd::string_view
ircd::fs::basepath::set(const base &base,
const string_view &path)
{
log::debug
{
log, "Updating base path #%u '%s' from `%' to `%s'",
uint(base),
basepaths.at(base).name,
basepaths.at(base).path,
path,
};
const string_view ret(basepaths.at(base).path);
basepaths.at(base).path = path;
return ret;
}
const ircd::fs::basepath & const ircd::fs::basepath &
ircd::fs::basepath::get(const base &base) ircd::fs::basepath::get(const base &base)
noexcept noexcept