mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-12 22:02:49 +01:00
Use stat when dirent doesn't know file type
This commit is contained in:
parent
f2ca6ed4d1
commit
3a3c8447aa
@ -4,6 +4,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
void FileIndex::indexDirectory(const std::string& directory)
|
void FileIndex::indexDirectory(const std::string& directory)
|
||||||
@ -19,8 +20,17 @@ void FileIndex::indexDirectory(const std::string& directory)
|
|||||||
realName = ep->d_name;
|
realName = ep->d_name;
|
||||||
lowerName = realName;
|
lowerName = realName;
|
||||||
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
||||||
if ( ep->d_type == DT_REG )
|
bool isRegularFile = false;
|
||||||
{
|
if (ep->d_type != DT_UNKNOWN) {
|
||||||
|
isRegularFile = ep->d_type == DT_REG;
|
||||||
|
} else {
|
||||||
|
std::string filepath = directory +"/"+ realName;
|
||||||
|
struct stat filedata;
|
||||||
|
if (stat(filepath.c_str(), &filedata) == 0) {
|
||||||
|
isRegularFile = S_ISREG(filedata.st_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isRegularFile) {
|
||||||
files[ lowerName ] = {
|
files[ lowerName ] = {
|
||||||
lowerName,
|
lowerName,
|
||||||
realName,
|
realName,
|
||||||
@ -43,10 +53,20 @@ void FileIndex::indexTree(const std::string& root)
|
|||||||
}
|
}
|
||||||
while( (ep = readdir(dp)) )
|
while( (ep = readdir(dp)) )
|
||||||
{
|
{
|
||||||
if( ep->d_type == DT_DIR && ep->d_name[0] != '.' )
|
std::string filepath = root +"/"+ ep->d_name;
|
||||||
{
|
|
||||||
std::string path = root + "/" + ep->d_name;
|
bool isDirectory = false;
|
||||||
indexTree(path);
|
if (ep->d_type != DT_UNKNOWN) {
|
||||||
|
isDirectory = ep->d_type == DT_DIR;
|
||||||
|
} else {
|
||||||
|
struct stat filedata;
|
||||||
|
if (stat(filepath.c_str(), &filedata) == 0) {
|
||||||
|
isDirectory = S_ISDIR(filedata.st_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDirectory && ep->d_name[0] != '.') {
|
||||||
|
indexTree(filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
|
Loading…
Reference in New Issue
Block a user