use S_ISREG instead of DT_REG for files

This commit is contained in:
Parastoo Ashtari 2021-12-03 14:03:31 -05:00
parent e6b663e8fb
commit 9c1a7ff640
1 changed files with 20 additions and 5 deletions

View File

@ -688,7 +688,10 @@ void DebugServices::ProcessConvertToHostFormat(const std::vector<std::string> &f
}
struct dirent *dir = nullptr;
while ((dir = readdir(d_handle)) != nullptr) {
if (dir->d_type == DT_REG) {
struct stat st;
std::string name = real_dump_iter_dir + std::string("/") + std::string(dir->d_name);
int ret = stat(name.c_str(), &st);
if (ret == 0 && S_ISREG(st.st_mode)) {
std::string candidate = dir->d_name;
for (const std::string &file_to_find : files_after_convert_in_dir) {
std::string file_n = file_to_find;
@ -782,7 +785,10 @@ void DebugServices::ProcessConvertList(const std::string &prefix_dump_file_name,
DIR *d = opendir(specific_dump_dir.c_str());
struct dirent *dir = nullptr;
while ((dir = readdir(d)) != nullptr) {
if (dir->d_type != DT_REG) {
struct stat st;
std::string name = specific_dump_dir + std::string("/") + std::string(dir->d_name);
int ret = stat(name.c_str(), &st);
if (!(ret == 0 && S_ISREG(st.st_mode))) {
continue;
}
std::string file_name = dir->d_name;
@ -997,7 +1003,10 @@ void DebugServices::ReadDumpedTensorSync(const std::string &prefix_dump_file_nam
} else {
struct dirent *dir = nullptr;
while ((dir = readdir(d)) != nullptr) {
if (dir->d_type == DT_REG) {
struct stat st;
std::string name = abspath + std::string("/") + std::string(dir->d_name);
int ret = stat(name.c_str(), &st);
if (ret == 0 && S_ISREG(st.st_mode)) {
std::string file_name = dir->d_name;
std::string stripped_file_name = GetStrippedFilename(file_name);
if (stripped_file_name.empty()) {
@ -1143,7 +1152,10 @@ void DebugServices::ProcessTensorDataSync(const std::vector<std::tuple<std::stri
} else {
struct dirent *dir = nullptr;
while ((dir = readdir(d)) != nullptr) {
if (dir->d_type == DT_REG) {
struct stat st;
std::string name = abspath + std::string("/") + std::string(dir->d_name);
int ret = stat(name.c_str(), &st);
if (ret == 0 && S_ISREG(st.st_mode)) {
std::string file_name = dir->d_name;
for (auto &node : proto_to_dump) {
std::string dump_name = std::get<1>(node);
@ -1338,7 +1350,10 @@ bool DebugServices::CheckOpOverflow(std::string node_name_to_find, unsigned int
} else {
struct dirent *dir = nullptr;
while ((dir = readdir(d)) != nullptr) {
if (dir->d_type == DT_REG) {
struct stat st;
std::string name = abspath + std::string("/") + std::string(dir->d_name);
int ret = stat(name.c_str(), &st);
if (ret == 0 && S_ISREG(st.st_mode)) {
// form fully qualified filename
std::string file_path = overflow_bin_path;
std::string file_name = dir->d_name;