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.
This commit is contained in:
Carlos Garnacho 2023-05-19 12:54:47 +02:00
parent eaaa2b5f66
commit 99571c42d5

View File

@ -23,6 +23,7 @@
#include "config.h"
#include <glib.h>
#include <gcancellable.h>
#include <glocalfileenumerator.h>
#include <glocalfileinfo.h>
#include <glocalfile.h>
@ -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;