summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-28 08:26:07 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-28 08:27:54 -0300
commit41a26528e4dc1e9204cbac20e3339ad89a2ed0ce (patch)
treee00847827fbb7a73f6e6d8365935d84896a5949c /tools
parente4eb025bfe86df44fed54f93babaa9b193991336 (diff)
Avoid recursion in filesystem scanning, closes #3838
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/editor_file_system.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/tools/editor/editor_file_system.cpp b/tools/editor/editor_file_system.cpp
index c5c92b5228..303f81477d 100644
--- a/tools/editor/editor_file_system.cpp
+++ b/tools/editor/editor_file_system.cpp
@@ -621,31 +621,40 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess
int total = dirs.size()+files.size();
int idx=0;
+
for (List<String>::Element *E=dirs.front();E;E=E->next(),idx++) {
if (da->change_dir(E->get())==OK) {
- EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory );
+ String d = da->get_current_dir();
- efd->parent=p_dir;
- efd->name=E->get();
+ if (d==cd || !d.begins_with(cd)) {
+ da->change_dir(cd); //avoid recursion
+ } else {
- _scan_new_dir(efd,da,p_progress.get_sub(idx,total));
- int idx=0;
- for(int i=0;i<p_dir->subdirs.size();i++) {
+ EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory );
- if (efd->name<p_dir->subdirs[i]->name)
- break;
- idx++;
- }
- if (idx==p_dir->subdirs.size()) {
- p_dir->subdirs.push_back(efd);
- } else {
- p_dir->subdirs.insert(idx,efd);
- }
+ efd->parent=p_dir;
+ efd->name=E->get();
+
+ _scan_new_dir(efd,da,p_progress.get_sub(idx,total));
+
+ int idx=0;
+ for(int i=0;i<p_dir->subdirs.size();i++) {
+
+ if (efd->name<p_dir->subdirs[i]->name)
+ break;
+ idx++;
+ }
+ if (idx==p_dir->subdirs.size()) {
+ p_dir->subdirs.push_back(efd);
+ } else {
+ p_dir->subdirs.insert(idx,efd);
+ }
- da->change_dir("..");
+ da->change_dir("..");
+ }
} else {
ERR_PRINTS(TTR("Cannot go into subdir:")+" "+E->get());
}