Prevent a class of crashes in monitoring

This commit is contained in:
Přemysl Eric Janouch 2023-08-03 04:34:05 +02:00
parent 1ec41f7749
commit 2d10aa8b61
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 3 additions and 1 deletions

View File

@ -346,6 +346,8 @@ static void
monitor_apply(enum monitor_event event, GPtrArray *target, int index, monitor_apply(enum monitor_event event, GPtrArray *target, int index,
FivIoModelEntry *new_entry) FivIoModelEntry *new_entry)
{ {
g_return_if_fail(event != MONITOR_CHANGING || index >= 0);
if (event == MONITOR_RENAMING && index < 0) if (event == MONITOR_RENAMING && index < 0)
// The file used to be filtered out but isn't anymore. // The file used to be filtered out but isn't anymore.
event = MONITOR_ADDING; event = MONITOR_ADDING;
@ -706,7 +708,7 @@ fiv_io_model_open(FivIoModel *self, GFile *directory, GError **error)
GError *e = NULL; GError *e = NULL;
if ((self->monitor = g_file_monitor_directory( if ((self->monitor = g_file_monitor_directory(
directory, G_FILE_MONITOR_WATCH_MOVES, NULL, &e))) { directory, G_FILE_MONITOR_WATCH_MOVES, NULL, &e))) {
g_signal_connect(self->monitor, "changed", g_signal_connect(self->monitor, "changed",
G_CALLBACK(on_monitor_changed), self); G_CALLBACK(on_monitor_changed), self);
} else { } else {