From 5abb6a2c08329839432b30f5d70b22ddac1dca1f Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Tue, 25 Jan 2022 11:38:44 +0100 Subject: Command line paths containing whitespace were getting truncated --- zenserver/config.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'zenserver/config.cpp') diff --git a/zenserver/config.cpp b/zenserver/config.cpp index 4afe012dd..3c4f6f3d8 100644 --- a/zenserver/config.cpp +++ b/zenserver/config.cpp @@ -91,6 +91,16 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) const char* DefaultHttp = "asio"; #endif + // Note to those adding future options; std::filesystem::path-type options + // must be read into a std::string first. As of cxxopts-3.0.0 it uses a >> + // stream operator to convert argv value into the options type. std::fs::path + // expects paths in streams to be quoted but argv paths are unquoted. By + // going into a std::string first, paths with whitespace parse correctly. + std::string DataDir; + std::string ContentDir; + std::string AbsLogFile; + std::string ConfigFile; + cxxopts::Options options("zenserver", "Zen Server"); options.add_options()("dedicated", "Enable dedicated server mode", @@ -99,10 +109,10 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) options.add_options()("help", "Show command line help"); options.add_options()("t, test", "Enable test mode", cxxopts::value(ServerOptions.IsTest)->default_value("false")); options.add_options()("log-id", "Specify id for adding context to log output", cxxopts::value(ServerOptions.LogId)); - options.add_options()("data-dir", "Specify persistence root", cxxopts::value(ServerOptions.DataDir)); - options.add_options()("content-dir", "Frontend content directory", cxxopts::value(ServerOptions.ContentDir)); - options.add_options()("abslog", "Path to log file", cxxopts::value(ServerOptions.AbsLogFile)); - options.add_options()("config", "Path to Lua config file", cxxopts::value(ServerOptions.ConfigFile)); + options.add_options()("data-dir", "Specify persistence root", cxxopts::value(DataDir)); + options.add_options()("content-dir", "Frontend content directory", cxxopts::value(ContentDir)); + options.add_options()("abslog", "Path to log file", cxxopts::value(AbsLogFile)); + options.add_options()("config", "Path to Lua config file", cxxopts::value(ConfigFile)); options.add_options()("no-sentry", "Disable Sentry crash handler", cxxopts::value(ServerOptions.NoSentry)->default_value("false")); @@ -327,6 +337,10 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) exit(0); } + ServerOptions.DataDir = DataDir; + ServerOptions.ContentDir = ContentDir; + ServerOptions.AbsLogFile = AbsLogFile; + ServerOptions.ConfigFile = ConfigFile; ServerOptions.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(UpstreamCachePolicyOptions); if (!ServerOptions.ConfigFile.empty()) -- cgit v1.2.3