Skip to content

Commit 702610e

Browse files
authored
fix the opt path create error in windows, test=develop (#33853) (#33885)
1 parent 3749af5 commit 702610e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

paddle/fluid/inference/analysis/helper.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,16 @@ static bool PathExists(const std::string &path) {
182182
}
183183

184184
static std::string GetDirRoot(const std::string &path) {
185-
char sep = '/';
186-
187-
#ifdef _WIN32
188-
sep = '\\';
189-
#endif
190-
191-
size_t i = path.rfind(sep, path.length());
192-
if (i != std::string::npos) {
193-
return (path.substr(0, i));
185+
char sep_1 = '/', sep_2 = '\\';
186+
187+
size_t i_1 = path.rfind(sep_1, path.length());
188+
size_t i_2 = path.rfind(sep_2, path.length());
189+
if (i_1 != std::string::npos && i_2 != std::string::npos) {
190+
return path.substr(0, std::max(i_1, i_2));
191+
} else if (i_1 != std::string::npos) {
192+
return path.substr(0, i_1);
193+
} else if (i_2 != std::string::npos) {
194+
return path.substr(0, i_2);
194195
}
195196
return path;
196197
}

0 commit comments

Comments
 (0)