--- madman-0.93rc2/utility/base.cpp.orig 2004-03-28 22:22:30 +0600 +++ madman-0.93rc2/utility/base.cpp.orig 2005-08-18 15:19:47 +0600 @@ -25,6 +25,7 @@ #include #include #include +#include #include "utility/progress.h" @@ -304,12 +305,12 @@ else realdir = directory; - try - { dir = opendir(realdir.c_str()); if (dir == NULL) throw runtime_error(("could not open directory: "+directory).c_str()); + try + { while ((entry = readdir(dir))) { if (strcmp(entry->d_name, ".") == 0) @@ -319,10 +320,21 @@ if (prog) prog->setProgress(prog->progress() + 1); - if (entry->d_type == DT_DIR) - enumerateFiles(realdir + "/" + entry->d_name, result, prog); - else if (entry->d_type == DT_REG) - result.push_back(realdir + "/" + entry->d_name); + string full_name = realdir + "/" + entry->d_name; + + struct stat my_statbuf; + if (stat(full_name.c_str(), &my_statbuf) != 0) + { + cerr + << "*** Failed to stat:" << endl + << "*** " << full_name << endl; + continue; + } + + if (S_ISDIR(my_statbuf.st_mode)) + enumerateFiles(full_name, result, prog); + else if (S_ISREG(my_statbuf.st_mode)) + result.push_back(full_name); } closedir(dir); @@ -330,6 +342,7 @@ catch (...) { closedir(dir); + throw; } }