Common: Replace ScanDirectoryTree with a non-recursive implementation.
This makes it do only what we need for our readdir implementation, thus improving performances a lot in heavy trees and fixing bugs like #1115.
This commit is contained in:
parent
76baf84763
commit
000fa3cf55
3 changed files with 17 additions and 11 deletions
|
@ -420,9 +420,7 @@ bool CreateEmptyFile(const std::string &filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Scans the directory tree gets, starting from _Directory and adds the
|
u32 ReadDirectory(const std::string& directory, FSTEntry& parentEntry, int recursion)
|
||||||
// results into parentEntry. Returns the number of files+directories found
|
|
||||||
u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
|
|
||||||
{
|
{
|
||||||
LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str());
|
LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str());
|
||||||
// How many files + directories we found
|
// How many files + directories we found
|
||||||
|
@ -467,12 +465,14 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
|
||||||
if (IsDirectory(entry.physicalName.c_str()))
|
if (IsDirectory(entry.physicalName.c_str()))
|
||||||
{
|
{
|
||||||
entry.isDirectory = true;
|
entry.isDirectory = true;
|
||||||
// is a directory, lets go inside
|
if (recursion > 0)
|
||||||
entry.size = ScanDirectoryTree(entry.physicalName, entry);
|
{
|
||||||
foundEntries += (u32)entry.size;
|
entry.size = ReadDirectory(entry.physicalName, entry, recursion - 1);
|
||||||
|
foundEntries += (u32)entry.size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // is a file
|
{
|
||||||
entry.isDirectory = false;
|
entry.isDirectory = false;
|
||||||
entry.size = GetSize(entry.physicalName.c_str());
|
entry.size = GetSize(entry.physicalName.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,9 +96,15 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename);
|
||||||
// creates an empty file filename, returns true on success
|
// creates an empty file filename, returns true on success
|
||||||
bool CreateEmptyFile(const std::string &filename);
|
bool CreateEmptyFile(const std::string &filename);
|
||||||
|
|
||||||
// Scans the directory tree gets, starting from _Directory and adds the
|
/**
|
||||||
// results into parentEntry. Returns the number of files+directories found
|
* Reads the contents of a directory, and adds the results into
|
||||||
u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry);
|
* parentEntry, optionally going down up to recursion levels.
|
||||||
|
* @param directory Path of the directory to scan.
|
||||||
|
* @param parentEntry Structure into which found files will be put.
|
||||||
|
* @param recursion Number of children directory to read before giving up.
|
||||||
|
* @returns u32 The number of files+directories found.
|
||||||
|
*/
|
||||||
|
u32 ReadDirectory(const std::string& directory, FSTEntry& parentEntry, int recursion = 0);
|
||||||
|
|
||||||
// deletes the given directory and anything under it. Returns true on success.
|
// deletes the given directory and anything under it. Returns true on success.
|
||||||
bool DeleteDirRecursively(const std::string &directory);
|
bool DeleteDirRecursively(const std::string &directory);
|
||||||
|
|
|
@ -144,7 +144,7 @@ DiskDirectory::DiskDirectory(const DiskArchive& archive, const Path& path) {
|
||||||
bool DiskDirectory::Open() {
|
bool DiskDirectory::Open() {
|
||||||
if (!FileUtil::IsDirectory(path))
|
if (!FileUtil::IsDirectory(path))
|
||||||
return false;
|
return false;
|
||||||
FileUtil::ScanDirectoryTree(path, directory);
|
FileUtil::ReadDirectory(path, directory);
|
||||||
children_iterator = directory.children.begin();
|
children_iterator = directory.children.begin();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue