[Xfce4-commits] <thunar:master> Prevent looping in some renamers.

Nick Schermer noreply at xfce.org
Sun Dec 4 12:58:01 CET 2011


Updating branch refs/heads/master
         to 57489635b994e33130ec2025ca7a73708f0ea3de (commit)
       from ea7bdab1438715fb0fdb755aa32d310c2b014cf8 (commit)

commit 57489635b994e33130ec2025ca7a73708f0ea3de
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Dec 4 12:52:35 2011 +0100

    Prevent looping in some renamers.
    
    Some renamers trigger file changes when processing the
    renamer name. Prevent this by checking if the disk content
    really changed.
    
    This is for example triggered by the thunar-media-tags-plugin
    in the bulk renamer. For an unknown reason, each time a file
    is read, the "changed" signal is triggered on the folder, resulting
    in endless looping on the file, consuming 100% cpu.

 thunar/thunar-renamer-model.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/thunar/thunar-renamer-model.c b/thunar/thunar-renamer-model.c
index 91a47e1..0b1ccfa 100644
--- a/thunar/thunar-renamer-model.c
+++ b/thunar/thunar-renamer-model.c
@@ -159,6 +159,7 @@ struct _ThunarRenamerModelItem
 {
   ThunarFile *file;
   gchar      *name;
+  guint64     date_changed;
   guint       changed : 1;  /* if the file changed */
   guint       conflict : 1; /* if the item conflicts with another item */
   guint       dirty : 1;    /* if the item must be updated */
@@ -592,6 +593,7 @@ thunar_renamer_model_file_changed (ThunarRenamerModel *renamer_model,
   GtkTreePath            *path;
   GtkTreeIter             iter;
   GList                  *lp;
+  guint64                 date_changed;
 
   _thunar_return_if_fail (THUNAR_IS_FILE (file));
   _thunar_return_if_fail (THUNAR_IS_FILE_MONITOR (file_monitor));
@@ -602,15 +604,24 @@ thunar_renamer_model_file_changed (ThunarRenamerModel *renamer_model,
   for (lp = renamer_model->items; lp != NULL; lp = lp->next)
     if (THUNAR_RENAMER_MODEL_ITEM (lp->data)->file == file)
       {
-        /* check if the file changed on disk */
         item = THUNAR_RENAMER_MODEL_ITEM (lp->data);
 
+        /* check if the file changed on disk, this is done to prevent
+         * excessive looping when some renamers are used
+         * (thunar-media-tags-plugin is an example) */
+        date_changed = thunar_file_get_date (file, THUNAR_FILE_DATE_CHANGED);
+        if (item->date_changed == date_changed)
+          break;
+
         /* check if we're frozen */
         if (G_LIKELY (!renamer_model->frozen))
           {
             /* the file changed */
             item->changed = TRUE;
 
+            /* set the new mtime */
+            item->date_changed = date_changed;
+
             /* invalidate the item */
             thunar_renamer_model_invalidate_item (renamer_model, item);
             break;
@@ -957,6 +968,7 @@ thunar_renamer_model_item_new (ThunarFile *file)
 
   item = g_slice_new0 (ThunarRenamerModelItem);
   item->file = g_object_ref (G_OBJECT (file));
+  item->date_changed = thunar_file_get_date (file, THUNAR_FILE_DATE_CHANGED);
   item->dirty = TRUE;
 
   return item;


More information about the Xfce4-commits mailing list