!23291 [MD] fix bug of mindrecord in windows

Merge pull request !23291 from liyong126/fix_bug_0911
This commit is contained in:
i-robot 2021-09-11 15:37:53 +00:00 committed by Gitee
commit b953d205bb
3 changed files with 15 additions and 6 deletions

View File

@ -81,8 +81,7 @@ Status GetFileName(const std::string &path, std::shared_ptr<std::string> *fn_ptr
}
#endif
std::string s = real_path;
char sep = '/';
size_t i = s.rfind(sep, s.length());
size_t i = s.rfind(kPathSeparator, s.length());
if (i != std::string::npos) {
if (i + 1 < s.size()) {
*fn_ptr = std::make_shared<std::string>(s.substr(i + 1));
@ -117,11 +116,13 @@ Status GetParentDir(const std::string &path, std::shared_ptr<std::string> *pd_pt
}
#endif
std::string s = real_path;
if (s.rfind('/') + 1 <= s.size()) {
*pd_ptr = std::make_shared<std::string>(s.substr(0, s.rfind('/') + 1));
if (s.rfind(kPathSeparator) + 1 <= s.size()) {
*pd_ptr = std::make_shared<std::string>(s.substr(0, s.rfind(kPathSeparator) + 1));
return Status::OK();
}
*pd_ptr = std::make_shared<std::string>("/");
std::string ss;
ss.push_back(kPathSeparator);
*pd_ptr = std::make_shared<std::string>(ss);
return Status::OK();
}

View File

@ -130,6 +130,13 @@ const std::unordered_map<std::string, std::string> kDbJsonMap = {
const char kPoint = '.';
const char kPathSeparator =
#if defined(_WIN32) || defined(_WIN64)
'\\';
#else
'/';
#endif
// field type used by check schema validation
const std::set<std::string> kFieldTypeSet = {"bytes", "string", "int32", "int64", "float32", "float64"};

View File

@ -52,7 +52,8 @@ Status ShardWriter::GetFullPathFromFileName(const std::vector<std::string> &path
RETURN_UNEXPECTED_IF_NULL(_fullpath(resolved_path, dirname(&(buf[0])), PATH_MAX));
RETURN_UNEXPECTED_IF_NULL(_fullpath(resolved_path, common::SafeCStr(path), PATH_MAX));
#else
RETURN_UNEXPECTED_IF_NULL(realpath(dirname(&(buf[0])), resolved_path));
CHECK_FAIL_RETURN_UNEXPECTED(realpath(dirname(&(buf[0])), resolved_path) != nullptr,
"Invalid file, path: " + std::string(resolved_path));
if (realpath(common::SafeCStr(path), resolved_path) == nullptr) {
MS_LOG(DEBUG) << "Path " << resolved_path;
}