summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-03-19 15:10:25 +0000
committerSadie Powell <sadie@witchery.services>2024-03-19 15:11:40 +0000
commitfde3438ef29447f41a6eb48049f8d620c1c2eb30 (patch)
treefcd2f03a9d5b693106ab545d3ffd08934149aee2 /src
parent1575dea5b96e7249d94ebc9214a73d123919c4ba (diff)
Allow using absolute paths in more places.
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp4
-rw-r--r--src/init.cpp7
-rw-r--r--src/logger.cpp2
-rw-r--r--src/misc.cpp24
-rw-r--r--src/module.cpp2
-rw-r--r--src/modulemanager.cpp8
6 files changed, 34 insertions, 13 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 6a8380464..7b322f8c9 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -697,7 +697,7 @@ const Anope::string &File::GetName() const
Anope::string File::GetPath() const
{
- return (this->executable ? "" : Anope::ConfigDir + "/") + this->name;
+ return this->executable ? this->name : Anope::ExpandConfig(this->name);
}
bool File::IsOpen() const
@@ -708,7 +708,7 @@ bool File::IsOpen() const
bool File::Open()
{
this->Close();
- this->fp = (this->executable ? popen(this->name.c_str(), "r") : fopen((Anope::ConfigDir + "/" + this->name).c_str(), "r"));
+ this->fp = (this->executable ? popen(GetPath().c_str(), "r") : fopen(GetPath().c_str(), "r"));
return this->fp != NULL;
}
diff --git a/src/init.cpp b/src/init.cpp
index fa7fcff15..7cb136844 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -417,12 +417,9 @@ bool Anope::Init(int ac, char **av)
}
Log(LOG_TERMINAL) << "Anope " << Anope::Version() << ", " << Anope::VersionBuildString();
+ Log(LOG_TERMINAL) << "Using configuration file " << Anope::ExpandConfig(ServicesConf.GetName());
-#ifdef _WIN32
- Log(LOG_TERMINAL) << "Using configuration file " << Anope::ConfigDir << "\\" << ServicesConf.GetName();
-#else
- Log(LOG_TERMINAL) << "Using configuration file " << Anope::ConfigDir << "/" << ServicesConf.GetName();
-
+#ifndef _WIN32
/* Fork to background */
if (!Anope::NoFork)
{
diff --git a/src/logger.cpp b/src/logger.cpp
index 9813ae150..6290831be 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -52,7 +52,7 @@ static inline Anope::string CreateLogName(const Anope::string &file, time_t t =
tm *tm = localtime(&t);
strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm);
- return Anope::LogDir + "/" + file + "." + timestamp;
+ return Anope::ExpandLog(file + "." + timestamp);
}
LogFile::LogFile(const Anope::string &name) : filename(name), stream(name.c_str(), std::ios_base::out | std::ios_base::app)
diff --git a/src/misc.cpp b/src/misc.cpp
index 1984477f7..861e6ee20 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -23,6 +23,7 @@
#include <climits>
#include <numeric>
#include <random>
+#include <filesystem>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef _WIN32
@@ -808,3 +809,26 @@ void Anope::UpdateTime()
CurTimeNs = tv.tv_usec * 1000;
#endif
}
+
+Anope::string Anope::Expand(const Anope::string& base, const Anope::string& fragment)
+{
+ // The fragment is an absolute path, don't modify it.
+ if (std::filesystem::path(fragment.str()).is_absolute())
+ return fragment;
+
+#ifdef _WIN32
+ static constexpr const char separator = '\\';
+#else
+ static constexpr const char separator = '/';
+#endif
+
+ // The fragment is relative to a home directory, expand that.
+ if (!fragment.compare(0, 2, "~/", 2))
+ {
+ const auto *homedir = getenv("HOME");
+ if (homedir && *homedir)
+ return Anope::printf("%s%c%s", homedir, separator, fragment.c_str() + 2);
+ }
+
+ return Anope::printf("%s%c%s", base.c_str(), separator, fragment.c_str());
+}
diff --git a/src/module.cpp b/src/module.cpp
index 63442e623..0511ad026 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -46,7 +46,7 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt
Anope::string lang;
sepstream(language, '.').GetToken(lang);
- if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo"))
+ if (Anope::IsFile(Anope::ExpandLocale(lang + "/LC_MESSAGES/" + modname + ".mo")))
{
if (!bindtextdomain(this->name.c_str(), Anope::LocaleDir.c_str()))
Log() << "Error calling bindtextdomain, " << Anope::LastError();
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index c350f8efd..96cb848b6 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -27,7 +27,7 @@ std::vector<Module *> ModuleManager::EventHandlers[I_SIZE];
#ifdef _WIN32
void ModuleManager::CleanupRuntimeDirectory()
{
- Anope::string dirbuf = Anope::DataDir + "/runtime";
+ Anope::string dirbuf = Anope::ExpandData("runtime");
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment, please wait";
try
@@ -55,7 +55,7 @@ void ModuleManager::CleanupRuntimeDirectory()
*/
static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &output)
{
- Anope::string input = Anope::ModuleDir + "/modules/" + name + DLL_EXT;
+ const auto input = Anope::ExpandModule("modules/" + name + DLL_EXT);
struct stat s;
if (stat(input.c_str(), &s) == -1)
@@ -133,7 +133,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
#ifdef _WIN32
/* Generate the filename for the temporary copy of the module */
- Anope::string pbuf = Anope::DataDir + "/runtime/" + modname + DLL_EXT ".XXXXXX";
+ const auto pbuf = Anope::ExpandData("runtime/" + modname + DLL_EXT ".XXXXXX");
/* Don't skip return value checking! -GD */
ModuleReturn ret = moduleCopyFile(modname, pbuf);
@@ -146,7 +146,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
return ret;
}
#else
- Anope::string pbuf = Anope::ModuleDir + "/modules/" + modname + DLL_EXT;
+ const auto pbuf = Anope::ExpandModule("modules/" + modname + DLL_EXT);
#endif
dlerror();