aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-08-26 13:37:19 +0200
committerGitHub <[email protected]>2022-08-26 04:37:19 -0700
commit57ba63d2f63847934b8d197a77c1eca292ed6e41 (patch)
treebce9d3038b3eadc83f6b330dee3300509ec550cf /zenserver
parentredefine vcpkg cache naming (diff)
downloadzen-57ba63d2f63847934b8d197a77c1eca292ed6e41.tar.xz
zen-57ba63d2f63847934b8d197a77c1eca292ed6e41.zip
Use "\\?\" prefixed paths and fix hardcoded path delimiters (#149)
* use "\\?\" prefix for windows paths * fix path delimiters * disable vcpkg caching * Workaround for spdlog not being able to create directories prefixed with `\\?\`
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/cache/structuredcachestore.cpp4
-rw-r--r--zenserver/config.cpp30
-rw-r--r--zenserver/diag/logging.cpp10
3 files changed, 35 insertions, 9 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 4e7ad522d..76a8707c5 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -871,7 +871,9 @@ ZenCacheDiskLayer::CacheBucket::BuildPath(PathBuilderBase& Path, const IoHash& H
ToHexBytes(HashKey.Hash, sizeof HashKey.Hash, HexString);
Path.Append(m_BucketDir);
- Path.Append(L"/blob/");
+ Path.AppendSeparator();
+ Path.Append(L"blob");
+ Path.AppendSeparator();
Path.AppendAsciiRange(HexString, HexString + 3);
Path.AppendSeparator();
Path.AppendAsciiRange(HexString + 3, HexString + 5);
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index c534865dc..6581b2109 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -487,8 +487,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
"");
try
{
- auto result = options.parse(argc, argv);
- ServerOptions.DataDir = DataDir;
+ auto result = options.parse(argc, argv);
if (result.count("help"))
{
@@ -503,10 +502,29 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
exit(0);
}
- ServerOptions.DataDir = DataDir;
- ServerOptions.ContentDir = ContentDir;
- ServerOptions.AbsLogFile = AbsLogFile;
- ServerOptions.ConfigFile = ConfigFile;
+ auto MakeSafePath = [](const std::string& Path) {
+#if ZEN_PLATFORM_WINDOWS
+ if (Path.empty())
+ {
+ return Path;
+ }
+
+ std::string FixedPath = Path;
+ std::replace(FixedPath.begin(), FixedPath.end(), '/', '\\');
+ if (!FixedPath.starts_with("\\\\?\\"))
+ {
+ FixedPath.insert(0, "\\\\?\\");
+ }
+ return FixedPath;
+#else
+ return Path;
+#endif
+ };
+
+ ServerOptions.DataDir = MakeSafePath(DataDir);
+ ServerOptions.ContentDir = MakeSafePath(ContentDir);
+ ServerOptions.AbsLogFile = MakeSafePath(AbsLogFile);
+ ServerOptions.ConfigFile = MakeSafePath(ConfigFile);
ServerOptions.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(UpstreamCachePolicyOptions);
if (!ServerOptions.ConfigFile.empty())
diff --git a/zenserver/diag/logging.cpp b/zenserver/diag/logging.cpp
index 3a5da2de9..887b0421d 100644
--- a/zenserver/diag/logging.cpp
+++ b/zenserver/diag/logging.cpp
@@ -203,7 +203,7 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
EnableVTMode();
std::filesystem::path LogPath =
- !GlobalOptions.AbsLogFile.empty() ? GlobalOptions.AbsLogFile : GlobalOptions.DataDir / "logs/zenserver.log";
+ !GlobalOptions.AbsLogFile.empty() ? GlobalOptions.AbsLogFile : GlobalOptions.DataDir / "logs" / "zenserver.log";
bool IsAsync = true;
spdlog::level::level_enum LogLevel = spdlog::level::info;
@@ -234,6 +234,9 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
auto ConsoleSink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>();
+ // spdlog can't create directories that starts with `\\?\` so we make sure the folder exists before creating the logger instance
+ zen::CreateDirectories(LogPath.parent_path());
+
#if 0
auto FileSink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(zen::PathToUtf8(LogPath),
0,
@@ -267,7 +270,10 @@ InitializeLogging(const ZenServerOptions& GlobalOptions)
// HTTP server request logging
- std::filesystem::path HttpLogPath = GlobalOptions.DataDir / "logs/http.log";
+ std::filesystem::path HttpLogPath = GlobalOptions.DataDir / "logs" / "http.log";
+
+ // spdlog can't create directories that starts with `\\?\` so we make sure the folder exists before creating the logger instance
+ zen::CreateDirectories(HttpLogPath.parent_path());
auto HttpSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(zen::PathToUtf8(HttpLogPath),
/* max size */ 128 * 1024 * 1024,