diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-04-24 19:27:07 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-04-24 19:27:07 +0300 |
commit | 6f58d1ee37041da28562d09757a9f653109f5677 (patch) | |
tree | 494b990338727f2adfdc7d7c6e46558be696aa29 /src/fs/virtfs/virtfsdir.cpp | |
parent | d1b635ebf238fac5911fde8982d067ee4ffffe3a (diff) | |
download | plus-6f58d1ee37041da28562d09757a9f653109f5677.tar.gz plus-6f58d1ee37041da28562d09757a9f653109f5677.tar.bz2 plus-6f58d1ee37041da28562d09757a9f653109f5677.tar.xz plus-6f58d1ee37041da28562d09757a9f653109f5677.zip |
Improve VirtFs::getFilesWithDir.
Diffstat (limited to 'src/fs/virtfs/virtfsdir.cpp')
-rw-r--r-- | src/fs/virtfs/virtfsdir.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfsdir.cpp b/src/fs/virtfs/virtfsdir.cpp index 967c80610..223b45e1d 100644 --- a/src/fs/virtfs/virtfsdir.cpp +++ b/src/fs/virtfs/virtfsdir.cpp @@ -138,6 +138,7 @@ namespace VirtFsDir ptr->openAppend = &VirtFsDir::openAppend; ptr->loadFile = &VirtFsDir::loadFile; ptr->getFiles = &VirtFsDir::getFiles; + ptr->getFilesWithDir = &VirtFsDir::getFilesWithDir; ptr->getDirs = &VirtFsDir::getDirs; ptr->rwops_seek = &VirtFsDir::rwops_seek; ptr->rwops_read = &VirtFsDir::rwops_read; @@ -563,6 +564,55 @@ namespace VirtFsDir } } + void getFilesWithDir(VirtFsEntry *restrict const entry, + const std::string &dirName, + StringVect &names) + { + const std::string path = entry->root + dirName; + const struct dirent *next_file = nullptr; + DIR *const dir = opendir(path.c_str()); + if (dir) + { + while ((next_file = readdir(dir))) + { + struct stat statbuf; + const std::string file = next_file->d_name; + if (file == "." || file == "..") + continue; +#ifndef WIN32 + if (mPermitLinks == false) + { + if (lstat(path.c_str(), &statbuf) == 0 && + S_ISLNK(statbuf.st_mode) != 0) + { + continue; + } + } +#endif // WIN32 + + const std::string filePath = pathJoin(path, file); + if (stat(filePath.c_str(), &statbuf) == 0) + { + if (S_ISDIR(statbuf.st_mode) != 0) + continue; + } + + bool found(false); + FOR_EACH (StringVectCIter, itn, names) + { + if (*itn == file) + { + found = true; + break; + } + } + if (found == false) + names.push_back(pathJoin(dirName, file)); + } + closedir(dir); + } + } + void getDirs(VirtFsEntry *restrict const entry, const std::string &dirName, StringVect &names) |