diff options
| author | Dan Engelbrecht <[email protected]> | 2022-08-26 13:37:19 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-26 04:37:19 -0700 |
| commit | 57ba63d2f63847934b8d197a77c1eca292ed6e41 (patch) | |
| tree | bce9d3038b3eadc83f6b330dee3300509ec550cf | |
| parent | redefine vcpkg cache naming (diff) | |
| download | zen-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 `\\?\`
| -rw-r--r-- | .github/workflows/create_release.yml | 36 | ||||
| -rw-r--r-- | .github/workflows/validate.yml | 36 | ||||
| -rw-r--r-- | zencore/filesystem.cpp | 7 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 4 | ||||
| -rw-r--r-- | zenserver/config.cpp | 30 | ||||
| -rw-r--r-- | zenserver/diag/logging.cpp | 10 |
6 files changed, 77 insertions, 46 deletions
diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index e669f24e9..9e3a430a9 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -28,12 +28,12 @@ jobs: .\vcpkg.exe integrate install cd .. - - name: Cache vcpkg - uses: actions/cache@v2 - with: - path: | - ${{ github.workspace }}\.vcpkg\installed - key: ${{ runner.os }}-bundle-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 +# - name: Cache vcpkg +# uses: actions/cache@v2 +# with: +# path: | +# ${{ github.workspace }}\.vcpkg\installed +# key: ${{ runner.os }}-bundle-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 - name: Config run: | @@ -84,12 +84,12 @@ jobs: ./bootstrap-vcpkg.sh cd .. - - name: Cache vcpkg - uses: actions/cache@v2 - with: - path: | - ${{ github.workspace }}/.vcpkg/installed - key: ${{ runner.os }}-bundle-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 +# - name: Cache vcpkg +# uses: actions/cache@v2 +# with: +# path: | +# ${{ github.workspace }}/.vcpkg/installed +# key: ${{ runner.os }}-bundle-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 - name: Config run: | @@ -147,12 +147,12 @@ jobs: ./bootstrap-vcpkg.sh cd .. - - name: Cache vcpkg - uses: actions/cache@v2 - with: - path: | - ${{ github.workspace }}/.vcpkg/installed - key: ${{ runner.os }}-bundle-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 +# - name: Cache vcpkg +# uses: actions/cache@v2 +# with: +# path: | +# ${{ github.workspace }}/.vcpkg/installed +# key: ${{ runner.os }}-bundle-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 - name: Config run: | diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a3d02b9fc..1a9dd2f12 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -73,12 +73,12 @@ jobs: .\vcpkg.exe integrate install cd .. - - name: Cache vcpkg - uses: actions/cache@v2 - with: - path: | - ${{ github.workspace }}\.vcpkg\installed - key: ${{ runner.os }}-validate-${{ matrix.config }}-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 +# - name: Cache vcpkg +# uses: actions/cache@v2 +# with: +# path: | +# ${{ github.workspace }}\.vcpkg\installed +# key: ${{ runner.os }}-validate-${{ matrix.config }}-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 - name: Config run: | @@ -144,12 +144,12 @@ jobs: ./bootstrap-vcpkg.sh cd .. - - name: Cache vcpkg - uses: actions/cache@v2 - with: - path: | - ${{ github.workspace }}/.vcpkg/installed - key: ${{ runner.os }}-validate-${{ matrix.config }}-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 +# - name: Cache vcpkg +# uses: actions/cache@v2 +# with: +# path: | +# ${{ github.workspace }}/.vcpkg/installed +# key: ${{ runner.os }}-validate-${{ matrix.config }}-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 - name: Config run: | @@ -209,12 +209,12 @@ jobs: ./bootstrap-vcpkg.sh cd .. - - name: Cache vcpkg - uses: actions/cache@v2 - with: - path: | - ${{ github.workspace }}/.vcpkg/installed - key: ${{ runner.os }}-validate-${{ matrix.config }}-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 +# - name: Cache vcpkg +# uses: actions/cache@v2 +# with: +# path: | +# ${{ github.workspace }}/.vcpkg/installed +# key: ${{ runner.os }}-validate-${{ matrix.config }}-${{env.VCPKG_VERSION}}-${{ hashFiles('xmake.lua') }}-${{ matrix.arch }}-v1 - name: Config run: | diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 01997daae..5e376ffda 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -189,7 +189,12 @@ bool CreateDirectories(const std::filesystem::path& Dir) { std::error_code ErrorCode; - return std::filesystem::create_directories(Dir, ErrorCode); + bool WasCreated = std::filesystem::create_directories(Dir, ErrorCode); + if (ErrorCode) + { + throw std::system_error(ErrorCode, fmt::format("Failed to create directories for '{}'", Dir.string())); + } + return WasCreated; } bool 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, |