From 702610efc58bcaeab3c88c0b222e21064581fc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=98=8E=E5=86=AC?= <78149749+winter-wang@users.noreply.github.com> Date: Thu, 1 Jul 2021 13:41:46 +0800 Subject: [PATCH] fix the opt path create error in windows, test=develop (#33853) (#33885) --- paddle/fluid/inference/analysis/helper.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/inference/analysis/helper.h b/paddle/fluid/inference/analysis/helper.h index cace420d87c..ebea4d03860 100644 --- a/paddle/fluid/inference/analysis/helper.h +++ b/paddle/fluid/inference/analysis/helper.h @@ -182,15 +182,16 @@ static bool PathExists(const std::string &path) { } static std::string GetDirRoot(const std::string &path) { - char sep = '/'; - -#ifdef _WIN32 - sep = '\\'; -#endif - - size_t i = path.rfind(sep, path.length()); - if (i != std::string::npos) { - return (path.substr(0, i)); + char sep_1 = '/', sep_2 = '\\'; + + size_t i_1 = path.rfind(sep_1, path.length()); + size_t i_2 = path.rfind(sep_2, path.length()); + if (i_1 != std::string::npos && i_2 != std::string::npos) { + return path.substr(0, std::max(i_1, i_2)); + } else if (i_1 != std::string::npos) { + return path.substr(0, i_1); + } else if (i_2 != std::string::npos) { + return path.substr(0, i_2); } return path; } -- GitLab