From 14d140ee60821463a54dc45576e5c2273d0c2802 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 5 Sep 2022 11:04:15 +0200 Subject: Fix/safer html folder detection (#153) * safer detection of html folder for frontend in debug mode * changelog --- zenserver/frontend/frontend.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'zenserver/frontend/frontend.cpp') diff --git a/zenserver/frontend/frontend.cpp b/zenserver/frontend/frontend.cpp index e203e0631..1b6fe6378 100644 --- a/zenserver/frontend/frontend.cpp +++ b/zenserver/frontend/frontend.cpp @@ -163,20 +163,30 @@ HttpFrontendService::HttpFrontendService(std::filesystem::path Directory) : m_Di } std::error_code ErrorCode; - for (auto Path = SelfPath.parent_path(); !Path.empty(); Path = Path.parent_path()) + auto Path = SelfPath; + while (Path.has_parent_path()) { - if (!std::filesystem::is_regular_file(Path / "xmake.lua", ErrorCode)) + auto ParentPath = Path.parent_path(); + if (ParentPath == Path) { - continue; + break; } - - auto HtmlDir = (Path / __FILE__).parent_path() / "html"; - if (std::filesystem::is_directory(HtmlDir, ErrorCode)) + if (std::filesystem::is_regular_file(ParentPath / "xmake.lua", ErrorCode)) { - m_Directory = HtmlDir; + if (ErrorCode) + { + break; + } + + auto HtmlDir = ParentPath / "zenserver" / "frontend" / "html"; + if (std::filesystem::is_directory(HtmlDir, ErrorCode)) + { + m_Directory = HtmlDir; + } + break; } - break; - } + Path = ParentPath; + }; #endif } -- cgit v1.2.3