From 99571c42d5ae6702340a4bf80207a2503f1e9249 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 19 May 2023 12:54:47 +0200 Subject: [PATCH] gio: Check cancellable iterating local file enumerator In the typical `while (g_file_enumerator_next_file ())` patterns, there is nothing much checking whether the operation was cancelled on the GIO side. Unless the user checks for the case, this means local enumerators always run to completion even if cancelled. Fix this by checking the cancellable state explicitly for local enumerators, so there are oportunities for bailing out early if the enumerator is going through a very large directory. --- gio/glocalfileenumerator.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gio/glocalfileenumerator.c b/gio/glocalfileenumerator.c index 21030bdc2..3694896a4 100644 --- a/gio/glocalfileenumerator.c +++ b/gio/glocalfileenumerator.c @@ -23,6 +23,7 @@ #include "config.h" #include +#include #include #include #include @@ -383,6 +384,9 @@ g_local_file_enumerator_next_file (GFileEnumerator *enumerator, next_file: + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return NULL; + #ifdef USE_GDIR filename = g_dir_read_name (local->dir); file_type = G_FILE_TYPE_UNKNOWN;