Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick]fix the opt path create error in windows. (#33853) #33885

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions paddle/fluid/inference/analysis/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down