[Xfce4-commits] <tumbler:master> Make Cleanup() take an array of base URIs instead of just one.

Jannis Pohlmann noreply at xfce.org
Sun Feb 13 13:42:01 CET 2011


Updating branch refs/heads/master
         to 7aad7803fe9875d8b651ab174607a1943ac30fa2 (commit)
       from 80a231891c5d1e43fb727ec007a4ab7b8aff468f (commit)

commit 7aad7803fe9875d8b651ab174607a1943ac30fa2
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Sun Feb 13 13:37:55 2011 +0100

    Make Cleanup() take an array of base URIs instead of just one.
    
    The thumbnail management D-Bus specification was updated accordingly.
    
    This change makes sense due to the following reason: when trashing a
    directory we cannot simply call org.freedesktop.thumbnails.Cache1.Delete
    as this will only remove the thumbnail of the directory itself, not of
    its descendants. But we can use the Cleanup method for this. With
    Cleanup taking an array of base URIs instead of just one we can avoid
    hundreds of Cleanup calls when trashing a large number of files.

 NEWS                                    |    6 +++
 plugins/xdg-cache/xdg-cache-cache.c     |   62 ++++++++++++++++++++++++++-----
 tumbler/tumbler-cache.c                 |   10 ++--
 tumbler/tumbler-cache.h                 |    6 +-
 tumblerd/tumbler-cache-service-dbus.xml |    2 +-
 tumblerd/tumbler-cache-service.c        |   16 +++++---
 tumblerd/tumbler-cache-service.h        |    4 +-
 7 files changed, 79 insertions(+), 27 deletions(-)

diff --git a/NEWS b/NEWS
index 376502b..37f5f11 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+0.1.x
+=====
+- Update to latest revision of the thumbnail management D-Bus 
+  specification where Cleanup() takes an array of base URIs instead
+  of just one.
+
 0.1.20
 ======
 - Version bump to override incompatibly versioned packages for Maemo.
diff --git a/plugins/xdg-cache/xdg-cache-cache.c b/plugins/xdg-cache/xdg-cache-cache.c
index 22a15a4..4f0e3b8 100644
--- a/plugins/xdg-cache/xdg-cache-cache.c
+++ b/plugins/xdg-cache/xdg-cache-cache.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -46,7 +46,7 @@ static TumblerThumbnail *xdg_cache_cache_get_thumbnail      (TumblerCache
                                                              const gchar            *uri,
                                                              TumblerThumbnailFlavor *flavor);
 static void              xdg_cache_cache_cleanup            (TumblerCache           *cache,
-                                                             const gchar            *uri_prefix,
+                                                             const gchar *const     *base_uris,
                                                              guint64                 since);
 static void              xdg_cache_cache_delete             (TumblerCache           *cache,
                                                              const GStrv             uris);
@@ -169,55 +169,97 @@ xdg_cache_cache_get_thumbnail (TumblerCache           *cache,
 
 
 static void
-xdg_cache_cache_cleanup (TumblerCache *cache,
-                         const gchar  *uri_prefix,
-                         guint64       since)
+xdg_cache_cache_cleanup (TumblerCache       *cache,
+                         const gchar *const *base_uris,
+                         guint64             since)
 {
   XDGCacheCache *xdg_cache = XDG_CACHE_CACHE (cache);
   const gchar   *file_basename;
   guint64        mtime;
+  GFile         *base_file;
   GFile         *dummy_file;
+  GFile         *original_file;
   GFile         *parent;
   GList         *iter;
   gchar         *dirname;
   gchar         *filename;
   gchar         *uri;
+  guint          n;
   GDir          *dir;
 
   g_return_if_fail (XDG_CACHE_IS_CACHE (cache));
-  
+
+  /* iterate over all flavors */
   for (iter = xdg_cache->flavors; iter != NULL; iter = iter->next)
     {
+      /* compute the flavor directory filename */
       dummy_file = xdg_cache_cache_get_file ("foo", iter->data);
       parent = g_file_get_parent (dummy_file);
       dirname = g_file_get_path (parent);
       g_object_unref (parent);
       g_object_unref (dummy_file);
 
+      /* attempt to open the directory for reading */
       dir = g_dir_open (dirname, 0, NULL);
-
       if (dir != NULL)
         {
-          while ((file_basename = g_dir_read_name (dir)) != NULL)
+          /* iterate over all files in the directory */
+          file_basename = g_dir_read_name (dir);
+          while (file_basename != NULL)
             {
+              /* build the thumbnail filename */
               filename = g_build_filename (dirname, file_basename, NULL);
 
+              /* read thumbnail information from the file */
               if (xdg_cache_cache_read_thumbnail_info (filename, &uri, &mtime, 
                                                        NULL, NULL))
                 {
-                  if ((uri_prefix == NULL || uri == NULL) 
-                      || (g_str_has_prefix (uri, uri_prefix) && (mtime <= since)))
+                  /* check if the thumbnail information is valid or the mtime
+                   * is too old */
+                  if (uri == NULL || mtime <= since) 
                     {
+                      /* it's invalid, so let's remove the thumbnail */
                       g_unlink (filename);
                     }
+                  else
+                    {
+                      /* create a GFile for the original URI. we need this for
+                       * reliably checking the ancestor/descendant relationship */
+                      original_file = g_file_new_for_uri (uri);
+
+                      for (n = 0; base_uris != NULL && base_uris[n] != NULL; ++n)
+                        {
+                          /* create a GFile for the base URI */
+                          base_file = g_file_new_for_uri (base_uris[n]);
+
+                          /* delete the file if it is a descendant of the base URI */
+                          if (g_file_equal (original_file, base_file)
+                              || g_file_has_prefix (original_file, base_file))
+                            {
+                              g_unlink (filename);
+                            }
+
+                          /* releas the base file */
+                          g_object_unref(base_file);
+                        }
+
+                      /* release the original file */
+                      g_object_unref (original_file);
+                    }
                 }
 
+              /* free the thumbnail filename */
               g_free (filename);
+
+              /* try to determine the next filename in the directory */
+              file_basename = g_dir_read_name (dir);
             }
 
+          /* close the handle used to reading from the directory */
           g_dir_close (dir);
         }
 
+      /* free the thumbnail flavor directory filename */
       g_free (dirname);
     }
 }
diff --git a/tumbler/tumbler-cache.c b/tumbler/tumbler-cache.c
index cc554dd..a147743 100644
--- a/tumbler/tumbler-cache.c
+++ b/tumbler/tumbler-cache.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -103,14 +103,14 @@ tumbler_cache_get_thumbnail (TumblerCache           *cache,
 
 
 void
-tumbler_cache_cleanup (TumblerCache *cache,
-                       const gchar  *uri_prefix,
-                       guint64       since)
+tumbler_cache_cleanup (TumblerCache       *cache,
+                       const gchar *const *base_uris,
+                       guint64             since)
 {
   g_return_if_fail (TUMBLER_IS_CACHE (cache));
   g_return_if_fail (TUMBLER_CACHE_GET_IFACE (cache)->cleanup != NULL);
 
-  (TUMBLER_CACHE_GET_IFACE (cache)->cleanup) (cache, uri_prefix, since);
+  (TUMBLER_CACHE_GET_IFACE (cache)->cleanup) (cache, base_uris, since);
 }
 
 
diff --git a/tumbler/tumbler-cache.h b/tumbler/tumbler-cache.h
index d8c447e..a2745b7 100644
--- a/tumbler/tumbler-cache.h
+++ b/tumbler/tumbler-cache.h
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -49,7 +49,7 @@ struct _TumblerCacheIface
                                       const gchar            *uri,
                                       TumblerThumbnailFlavor *flavor);
   void              (*cleanup)       (TumblerCache           *cache,
-                                      const gchar            *uri,
+                                      const gchar *const     *base_uris,
                                       guint64                 since);
   void              (*do_delete)     (TumblerCache           *cache,
                                       const GStrv             uris);
@@ -72,7 +72,7 @@ TumblerThumbnail       *tumbler_cache_get_thumbnail  (TumblerCache           *ca
                                                       const gchar            *uri,
                                                       TumblerThumbnailFlavor *flavor) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 void                    tumbler_cache_cleanup        (TumblerCache           *cache,
-                                                      const gchar            *uri_prefix,
+                                                      const gchar *const     *base_uris,
                                                       guint64                 since);
 void                    tumbler_cache_delete         (TumblerCache           *cache,
                                                       const GStrv             uris);
diff --git a/tumblerd/tumbler-cache-service-dbus.xml b/tumblerd/tumbler-cache-service-dbus.xml
index 0d4ca87..92ffa42 100644
--- a/tumblerd/tumbler-cache-service-dbus.xml
+++ b/tumblerd/tumbler-cache-service-dbus.xml
@@ -20,7 +20,7 @@
 
     <method name="Cleanup">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg type="s" name="uri_prefix" direction="in" />
+      <arg type="as" name="base_uris" direction="in" />
       <arg type="u" name="since" direction="in" />
     </method>
   </interface>
diff --git a/tumblerd/tumbler-cache-service.c b/tumblerd/tumbler-cache-service.c
index 659a666..6a6f36f 100644
--- a/tumblerd/tumbler-cache-service.c
+++ b/tumblerd/tumbler-cache-service.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as
@@ -116,7 +116,7 @@ struct _DeleteRequest
 struct _CleanupRequest
 {
   guint32 since;
-  gchar  *uri_prefix;
+  GStrv   base_uris;
 };
 
 
@@ -325,9 +325,13 @@ tumbler_cache_service_cleanup_thread (gpointer data,
   g_mutex_lock (service->mutex);
 
   if (service->cache != NULL)
-    tumbler_cache_cleanup (service->cache, request->uri_prefix, request->since);
+    {
+      tumbler_cache_cleanup (service->cache, 
+                             (const gchar *const *)request->base_uris, 
+                             request->since);
+    }
 
-  g_free (request->uri_prefix);
+  g_strfreev (request->base_uris);
   g_slice_free (CleanupRequest, request);
 
   g_mutex_unlock (service->mutex);
@@ -474,7 +478,7 @@ tumbler_cache_service_delete (TumblerCacheService   *service,
 
 void
 tumbler_cache_service_cleanup (TumblerCacheService   *service,
-                               const gchar           *uri_prefix,
+                               const gchar *const    *base_uris,
                                guint32                since,
                                DBusGMethodInvocation *context)
 {
@@ -483,7 +487,7 @@ tumbler_cache_service_cleanup (TumblerCacheService   *service,
   dbus_async_return_if_fail (TUMBLER_IS_CACHE_SERVICE (service), context);
 
   request = g_slice_new0 (CleanupRequest);
-  request->uri_prefix = g_strdup (uri_prefix);
+  request->base_uris = g_strdupv ((gchar **)base_uris);
   request->since = since;
 
   g_thread_pool_push (service->cleanup_pool, request, NULL);
diff --git a/tumblerd/tumbler-cache-service.h b/tumblerd/tumbler-cache-service.h
index 547fbdb..bb58a31 100644
--- a/tumblerd/tumbler-cache-service.h
+++ b/tumblerd/tumbler-cache-service.h
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2009-2011 Jannis Pohlmann <jannis at xfce.org>
  *
  * This program is free software; you can redistribute it and/or 
  * modify it under the terms of the GNU General Public License as
@@ -54,7 +54,7 @@ void                 tumbler_cache_service_delete  (TumblerCacheService   *servi
                                                     const GStrv            uris,
                                                     DBusGMethodInvocation *context);
 void                 tumbler_cache_service_cleanup (TumblerCacheService   *service,
-                                                    const gchar           *uri_prefix,
+                                                    const gchar *const    *uri_prefix,
                                                     guint32                since,
                                                     DBusGMethodInvocation *context);
 



More information about the Xfce4-commits mailing list