From 57489635b994e33130ec2025ca7a73708f0ea3de Mon Sep 17 00:00:00 2001 From: Nick Schermer <nick@xfce.org> Date: Sun, 4 Dec 2011 12:52:35 +0100 Subject: [PATCH] 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 file changed, 13 insertions(+), 1 deletion(-) diff --git a/thunar/thunar-renamer-model.c b/thunar/thunar-renamer-model.c index 91a47e14c..0b1ccfa8a 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; -- GitLab