[geany/geany-plugins] db9151: projectorganizer: Don't keep directories open when enumerating their children

Jiří Techet git-noreply at xxxxx
Thu Sep 28 09:25:46 UTC 2017


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Thu, 28 Sep 2017 09:25:46 UTC
Commit:      db915152e9dcf772d3f9a37878a556715d775a21
             https://github.com/geany/geany-plugins/commit/db915152e9dcf772d3f9a37878a556715d775a21

Log Message:
-----------
projectorganizer: Don't keep directories open when enumerating their children

At the moment the code calls g_dir_open() for the current dir, then
recurses to its children and finally closes the dir. This makes the
intermediate dirs open until the recursion returns and could potentially
cause too many open fd if the directory structure is extremely deep.

Instead, get all children of a directory first, close the directory and
then recurse into the remembered subdirectories.


Modified Paths:
--------------
    projectorganizer/src/prjorg-project.c

Modified: projectorganizer/src/prjorg-project.c
16 lines changed, 11 insertions(+), 5 deletions(-)
===================================================================
@@ -74,6 +74,9 @@ static GSList *get_file_list(const gchar *utf8_path, GSList *patterns,
 {
 	GSList *list = NULL;
 	GDir *dir;
+	const gchar *child_name;
+	GSList *child;
+	GSList *children = NULL;
 	gchar *locale_path = utils_get_locale_from_utf8(utf8_path);
 	gchar *real_path = tm_get_real_path(locale_path);
 
@@ -89,14 +92,17 @@ static GSList *get_file_list(const gchar *utf8_path, GSList *patterns,
 
 	g_hash_table_insert(visited_paths, real_path, GINT_TO_POINTER(1));
 
-	while (TRUE)
+	while ((child_name = g_dir_read_name(dir)))
+		children = g_slist_prepend(children, g_strdup(child_name));
+
+	g_dir_close(dir);
+
+	foreach_slist(child, children)
 	{
 		const gchar *locale_name;
 		gchar *locale_filename, *utf8_filename, *utf8_name;
 
-		locale_name = g_dir_read_name(dir);
-		if (!locale_name)
-			break;
+		locale_name = child->data;
 
 		utf8_name = utils_get_utf8_from_locale(locale_name);
 		locale_filename = g_build_filename(locale_path, locale_name, NULL);
@@ -125,7 +131,7 @@ static GSList *get_file_list(const gchar *utf8_path, GSList *patterns,
 		g_free(utf8_name);
 	}
 
-	g_dir_close(dir);
+	g_slist_free_full(children, g_free);
 	g_free(locale_path);
 
 	return list;



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list