From 2fd31c6c8d77637a828c09b2d0ac3e9ba3ccbfa6 Mon Sep 17 00:00:00 2001 From: Meeh Date: Sat, 1 Feb 2014 04:51:58 +0100 Subject: [PATCH] Custom datadir + cleanup --- i2p.cpp | 11 +---------- util.cpp | 27 +++++++++++++++++---------- util.h | 1 + 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/i2p.cpp b/i2p.cpp index 82a69671..aed38cd0 100644 --- a/i2p.cpp +++ b/i2p.cpp @@ -24,16 +24,7 @@ int main( int argc, char* argv[] ) #endif LogPrint("\n\n\n\ni2pd starting\n"); - LogPrint("default data directory: ", i2p::util::filesystem::GetDefaultDataDir().string()); - if (!boost::filesystem::exists( i2p::util::filesystem::GetDefaultDataDir() )) - { - // Create data directory - if (!boost::filesystem::create_directory( i2p::util::filesystem::GetDefaultDataDir() )) - { - LogPrint("Failed to create data directory, exiting! :("); - return -1; - } - } + LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string()); i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs); //TODO: This is an ugly workaround. fix it. diff --git a/util.cpp b/util.cpp index 2da8fdb5..1c64cc75 100644 --- a/util.cpp +++ b/util.cpp @@ -89,30 +89,37 @@ namespace config namespace filesystem { - const boost::filesystem::path &GetDataDir(bool fNetSpecific) + const boost::filesystem::path &GetDataDir() { static boost::filesystem::path path; - if (config::mapArgs.count("-datadir")) { - path = boost::filesystem::system_complete(config::mapArgs["-datadir"]); - if (!boost::filesystem::is_directory(path)) { - path = ""; - return path; - } + if (i2p::util::config::mapArgs.count("-datadir")) { + path = boost::filesystem::system_complete(i2p::util::config::mapArgs["-datadir"]); } else { path = GetDefaultDataDir(); } - boost::filesystem::create_directory(path); - + if (!boost::filesystem::exists( path )) + { + // Create data directory + if (!boost::filesystem::create_directory( path )) + { + LogPrint("Failed to create data directory!"); + return ""; + } + } + if (!boost::filesystem::is_directory(path)) { + path = GetDefaultDataDir(); + } + LogPrint("Debug: ",path.string()); return path; } boost::filesystem::path GetConfigFile() { boost::filesystem::path pathConfigFile(i2p::util::config::GetArg("-conf", "i2p.conf")); - if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile; + if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile; return pathConfigFile; } diff --git a/util.h b/util.h index 7f22e3f1..7090294f 100644 --- a/util.h +++ b/util.h @@ -22,6 +22,7 @@ namespace util namespace filesystem { + const boost::filesystem::path &GetDataDir(); boost::filesystem::path GetDefaultDataDir(); boost::filesystem::path GetConfigFile(); void ReadConfigFile(std::map& mapSettingsRet,