Skip to content

Commit

Permalink
gnome-desktop-thumbnailer.c: Make sure a thumbnailer's binary is
Browse files Browse the repository at this point in the history
found in the path before deciding to use it.

This would cause an invalid thumbnailer to prevent a valid one
from registering, breaking thumbnailing for those mimetypes until
the invalid one was fixed or removed.

ref: linuxmint/linuxmint#452
  • Loading branch information
mtwebster committed Jan 11, 2022
1 parent 854f16a commit 51fe36d
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions libcinnamon-desktop/gnome-desktop-thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ thumbnailer_load (Thumbnailer *thumb)
}

thumb->try_exec = g_key_file_get_string (key_file, THUMBNAILER_ENTRY_GROUP, "TryExec", NULL);
if (thumb->try_exec != NULL)
{
gchar *path_to_exec = g_find_program_in_path (thumb->try_exec);

if (path_to_exec == NULL)
{
g_message ("Ignoring thumbnailer with missing binary: '%s'", thumb->try_exec);
thumbnailer_unref (thumb);
g_key_file_free (key_file);
return NULL;
}

g_free (path_to_exec);
}

g_key_file_free (key_file);

Expand Down Expand Up @@ -211,28 +225,6 @@ thumbnailer_new (const gchar *path)
return thumbnailer_load (thumb);
}

static gboolean
thumbnailer_try_exec (Thumbnailer *thumb)
{
gchar *path;
gboolean retval;

if (G_UNLIKELY (!thumb))
return FALSE;

/* TryExec is optinal, but Exec isn't, so we assume
* the thumbnailer can be run when TryExec is not present
*/
if (!thumb->try_exec)
return TRUE;

path = g_find_program_in_path (thumb->try_exec);
retval = path != NULL;
g_free (path);

return retval;
}

static gpointer
init_thumbnailers_dirs (gpointer data)
{
Expand Down Expand Up @@ -1087,9 +1079,6 @@ gnome_desktop_thumbnail_factory_can_thumbnail (GnomeDesktopThumbnailFactory *fac
const char *mime_type,
time_t mtime)
{
gboolean have_script = FALSE;


if (factory->priv->permissions_problem)
return FALSE;

Expand All @@ -1111,11 +1100,10 @@ gnome_desktop_thumbnail_factory_can_thumbnail (GnomeDesktopThumbnailFactory *fac

Thumbnailer *thumb;
thumb = g_hash_table_lookup (factory->priv->mime_types_map, mime_type);
have_script = thumbnailer_try_exec (thumb);

g_mutex_unlock (&factory->priv->lock);

if (have_script || mimetype_supported_by_gdk_pixbuf (mime_type))
if (thumb || mimetype_supported_by_gdk_pixbuf (mime_type))
{
return !gnome_desktop_thumbnail_factory_has_valid_failed_thumbnail (factory,
uri,
Expand Down

0 comments on commit 51fe36d

Please sign in to comment.