diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-07-30 00:12:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-30 00:12:30 +0200 |
commit | 73d2a997616be6b91bc1fecbf4745abe88f85a92 (patch) | |
tree | 04a21d02ca9c61156167285886c4cb5b4cda7e86 | |
parent | 14e3d29f0c371dff734e7da9b6fcb49c7d367606 (diff) | |
parent | e02c5ef48ac50f66d7702e4be19282122acf1b0d (diff) |
Merge pull request #30911 from hadrien-psydk/optimize_dir_access_unix_get_next_lnk
Optimize DirAccessUnix::get_next() for some file systems (with link support)
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 251bab5783..6817137a94 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -126,37 +126,32 @@ String DirAccessUnix::get_next() { if (!dir_stream) return ""; - dirent *entry; - entry = readdir(dir_stream); + dirent *entry = readdir(dir_stream); if (entry == NULL) { - list_dir_end(); return ""; } - //typedef struct stat Stat; - struct stat flags; - String fname = fix_unicode_name(entry->d_name); - String f = current_dir.plus_file(fname); - - if (stat(f.utf8().get_data(), &flags) == 0) { - - if (S_ISDIR(flags.st_mode)) { - - _cisdir = true; - + // Look at d_type to determine if the entry is a directory, unless + // its type is unknown (the file system does not support it) or if + // the type is a link, in that case we want to resolve the link to + // known if it points to a directory. stat() will resolve the link + // for us. + if (entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK) { + String f = current_dir.plus_file(fname); + + struct stat flags; + if (stat(f.utf8().get_data(), &flags) == 0) { + _cisdir = S_ISDIR(flags.st_mode); } else { - _cisdir = false; } - } else { - - _cisdir = false; + _cisdir = (entry->d_type == DT_DIR); } _cishidden = (fname != "." && fname != ".." && fname.begins_with(".")); |