Prevent endless recursive directory scans
This can happen when a folder symlinks to itself or subfolders in some similar recursive pattern.
This commit is contained in:
parent
e8162a421d
commit
d257c8c0ce
@ -22,6 +22,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include <glib.h>
|
||||
@ -80,7 +81,8 @@ run_functor_for_paths (vector<string>& result,
|
||||
void *arg,
|
||||
bool pass_files_only,
|
||||
bool pass_fullpath, bool return_fullpath,
|
||||
bool recurse)
|
||||
bool recurse,
|
||||
set<string>& scanned_paths)
|
||||
{
|
||||
for (vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
|
||||
try
|
||||
@ -102,11 +104,12 @@ run_functor_for_paths (vector<string>& result,
|
||||
bool is_dir = Glib::file_test (fullpath, Glib::FILE_TEST_IS_DIR);
|
||||
|
||||
if (is_dir && recurse) {
|
||||
DEBUG_TRACE (DEBUG::FileUtils,
|
||||
string_compose("Descending into directory: %1\n",
|
||||
fullpath));
|
||||
run_functor_for_paths (result, fullpath, functor, arg, pass_files_only,
|
||||
pass_fullpath, return_fullpath, recurse);
|
||||
if (scanned_paths.find (fullpath) == scanned_paths.end ()) {
|
||||
scanned_paths.insert (fullpath);
|
||||
DEBUG_TRACE (DEBUG::FileUtils, string_compose("Descending into directory: %1\n", fullpath));
|
||||
run_functor_for_paths (result, fullpath, functor, arg, pass_files_only,
|
||||
pass_fullpath, return_fullpath, recurse, scanned_paths);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_dir && pass_files_only) {
|
||||
@ -163,8 +166,9 @@ get_paths (vector<string>& result,
|
||||
bool files_only,
|
||||
bool recurse)
|
||||
{
|
||||
set<string> scanned_path;
|
||||
run_functor_for_paths (result, paths, accept_all_files, 0,
|
||||
files_only, true, true, recurse);
|
||||
files_only, true, true, recurse, scanned_path);
|
||||
}
|
||||
|
||||
void
|
||||
@ -186,9 +190,10 @@ find_files_matching_pattern (vector<string>& result,
|
||||
const Searchpath& paths,
|
||||
const Glib::PatternSpec& pattern)
|
||||
{
|
||||
set<string> unused;
|
||||
run_functor_for_paths (result, paths, pattern_filter,
|
||||
const_cast<Glib::PatternSpec*>(&pattern),
|
||||
true, false, true, false);
|
||||
true, false, true, false, unused);
|
||||
}
|
||||
|
||||
void
|
||||
@ -281,7 +286,8 @@ find_paths_matching_filter (vector<string>& result,
|
||||
bool pass_fullpath, bool return_fullpath,
|
||||
bool recurse)
|
||||
{
|
||||
run_functor_for_paths (result, paths, filter, arg, false, pass_fullpath, return_fullpath, recurse);
|
||||
set<string> scanned_path;
|
||||
run_functor_for_paths (result, paths, filter, arg, false, pass_fullpath, return_fullpath, recurse, scanned_path);
|
||||
}
|
||||
|
||||
void
|
||||
@ -292,7 +298,8 @@ find_files_matching_filter (vector<string>& result,
|
||||
bool pass_fullpath, bool return_fullpath,
|
||||
bool recurse)
|
||||
{
|
||||
run_functor_for_paths (result, paths, filter, arg, true, pass_fullpath, return_fullpath, recurse);
|
||||
set<string> scanned_path;
|
||||
run_functor_for_paths (result, paths, filter, arg, true, pass_fullpath, return_fullpath, recurse, scanned_path);
|
||||
}
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user