From 32e94931a78d558bb0837c05d7ee2d4a2a310478 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 6 Jun 2019 17:11:54 -0700 Subject: [PATCH] ircd::fs: Add ability to change basepath values at runtime. --- include/ircd/fs/path.h | 3 +++ ircd/fs.cc | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/ircd/fs/path.h b/include/ircd/fs/path.h index 3e3747d19..89e340c8a 100644 --- a/include/ircd/fs/path.h +++ b/include/ircd/fs/path.h @@ -62,12 +62,15 @@ namespace ircd::fs /// 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). +/// 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 { string_view name; string_view path; 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. diff --git a/ircd/fs.cc b/ircd/fs.cc index 87856392c..8778083db 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -2225,7 +2225,7 @@ catch(const filesystem::filesystem_error &e) namespace ircd::fs { - extern const std::array()> basepaths; + extern std::array()> basepaths; } decltype(ircd::fs::basepaths) @@ -2240,6 +2240,24 @@ ircd::fs::basepaths { "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 & ircd::fs::basepath::get(const base &base) noexcept