From ae3e618c29a3e060f5ebaa0362123676b502bd41 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 7 Jul 2015 17:45:43 +0100 Subject: [PATCH 4/4] xdg-cache: Store removable media thumbnails on removable media MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This means the files don’t have to be re-thumbnailed for every computer the drive is mounted on; and conversely, each computer doesn’t have to worry about the cache lifetime of files on removable disks which it may never see again. Based on a patch by Jeremy Whiting . https://bugzilla.xfce.org/show_bug.cgi?id=12036 --- plugins/xdg-cache/xdg-cache-thumbnail.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/xdg-cache/xdg-cache-thumbnail.c b/plugins/xdg-cache/xdg-cache-thumbnail.c index ce5137c..add7996 100644 --- a/plugins/xdg-cache/xdg-cache-thumbnail.c +++ b/plugins/xdg-cache/xdg-cache-thumbnail.c @@ -310,7 +310,35 @@ xdg_cache_thumbnail_needs_update (TumblerThumbnail *thumbnail, || cache_thumbnail->cached_mtime != mtime; } +static gboolean +is_uri_removable (const gchar *uri) +{ + GFile *file = NULL; + GMount *mount = NULL; + gboolean is_removable; + GError *error = NULL; + + file = g_file_new_for_uri (uri); + mount = g_file_find_enclosing_mount (file, NULL, &error); + + if (mount != NULL) { + is_removable = g_mount_can_eject (mount); + } else { + g_debug ("%s: Error finding enclosing mount for ‘%s’: %s", + G_STRFUNC, uri, error->message); + g_error_free (error); + + is_removable = FALSE; + } + g_clear_object (&mount); + g_clear_object (&file); + + g_debug ("%s: Determined URI ‘%s’ %s removable.", + G_STRFUNC, uri, is_removable ? "is" : "is not"); + + return is_removable; +} static gboolean xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail, @@ -351,7 +379,7 @@ xdg_cache_thumbnail_save_image_data (TumblerThumbnail *thumbnail, * * See: http://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#SHARED */ - shared = FALSE; + shared = is_uri_removable (cache_thumbnail->uri); /* determine dimensions of the thumbnail pixbuf */ width = data->width; -- 2.4.3