Skip to content

Commit

Permalink
Handle cases when file watch is not supported (Bug #13881)
Browse files Browse the repository at this point in the history
When a remote folder is accessed, this error is printed:
(thunar:9378): thunar-CRITICAL **: thunar_file_watch: assertion '...

Upon leaving that folder, Thunar crashes:
ERROR:thunar-file.c:3929:thunar_file_unwatch: code should not be reached

I found out that a call to g_file_monitor in thunar_file_watch has no
error handling, and in the case of remote folders this error happens:
Failed to create file monitor: Operation not supported by backend

So when ThunarFolder is finalized and calls thunar_file_unwatch, its
file_watch will be NULL and _thunar_assert_not_reached kills Thunar.
  • Loading branch information
Andre Miranda committed Nov 4, 2017
1 parent 7792a3f commit ab50af4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions thunar/thunar-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ struct _ThunarFile

/* flags for thumbnail state etc */
ThunarFileFlags flags;

/* tells whether the file watch is not set */
gboolean no_file_watch;
};

typedef struct
Expand Down Expand Up @@ -3875,6 +3878,7 @@ void
thunar_file_watch (ThunarFile *file)
{
ThunarFileWatch *file_watch;
GError *error = NULL;

_thunar_return_if_fail (THUNAR_IS_FILE (file));

Expand All @@ -3885,8 +3889,14 @@ thunar_file_watch (ThunarFile *file)
file_watch->watch_count = 1;

/* create a file or directory monitor */
file_watch->monitor = g_file_monitor (file->gfile, G_FILE_MONITOR_WATCH_MOUNTS | G_FILE_MONITOR_SEND_MOVED, NULL, NULL);
if (G_LIKELY (file_watch->monitor != NULL))
file_watch->monitor = g_file_monitor (file->gfile, G_FILE_MONITOR_WATCH_MOUNTS | G_FILE_MONITOR_SEND_MOVED, NULL, &error);
if (G_UNLIKELY (file_watch->monitor == NULL))
{
g_debug ("Failed to create file monitor: %s", error->message);
g_error_free (error);
file->no_file_watch = TRUE;
}
else
{
/* watch monitor for file changes */
g_signal_connect (file_watch->monitor, "changed", G_CALLBACK (thunar_file_monitor), file);
Expand All @@ -3895,7 +3905,7 @@ thunar_file_watch (ThunarFile *file)
/* attach to file */
g_object_set_qdata_full (G_OBJECT (file), thunar_file_watch_quark, file_watch, thunar_file_watch_destroyed);
}
else
else if (G_LIKELY (!file->no_file_watch))
{
/* increase watch count */
_thunar_return_if_fail (G_IS_FILE_MONITOR (file_watch->monitor));
Expand All @@ -3919,6 +3929,11 @@ thunar_file_unwatch (ThunarFile *file)

_thunar_return_if_fail (THUNAR_IS_FILE (file));

if (G_UNLIKELY (file->no_file_watch))
{
return;
}

file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
if (file_watch != NULL)
{
Expand Down

0 comments on commit ab50af4

Please sign in to comment.