summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfsdir.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-24 03:35:02 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-24 04:35:35 +0300
commit0835e09ee3a6c83ffa01454f2c05597e6195b07d (patch)
treeb3b79b7a8f58f2ff18ec66b17d1c39ddad085e11 /src/fs/virtfs/virtfsdir.cpp
parent55458f743c3ff7e42288bc08033481d8464dca62 (diff)
downloadplus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.tar.gz
plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.tar.bz2
plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.tar.xz
plus-0835e09ee3a6c83ffa01454f2c05597e6195b07d.zip
Improve VirtFs::getFiles.
Diffstat (limited to 'src/fs/virtfs/virtfsdir.cpp')
-rw-r--r--src/fs/virtfs/virtfsdir.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfsdir.cpp b/src/fs/virtfs/virtfsdir.cpp
index 9eac0896b..2d165195e 100644
--- a/src/fs/virtfs/virtfsdir.cpp
+++ b/src/fs/virtfs/virtfsdir.cpp
@@ -137,6 +137,7 @@ namespace VirtFsDir
ptr->openWrite = &VirtFsDir::openWrite;
ptr->openAppend = &VirtFsDir::openAppend;
ptr->loadFile = &VirtFsDir::loadFile;
+ ptr->getFiles = &VirtFsDir::getFiles;
ptr->rwops_seek = &VirtFsDir::rwops_seek;
ptr->rwops_read = &VirtFsDir::rwops_read;
ptr->rwops_write = &VirtFsDir::rwops_write;
@@ -511,4 +512,54 @@ namespace VirtFsDir
return buffer;
}
+
+ void getFiles(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(file);
+ }
+ closedir(dir);
+ }
+ }
+
} // namespace VirtFs