[shotwell] Fix crash during metadate update (#739917)



commit 66a2a49ad924dd4403f642103f8f324c60c6c3ef
Author: Wolfgang Steitz <wsteitz gmail com>
Date:   Fri Apr 3 10:21:15 2015 +0200

    Fix crash during metadate update (#739917)
    
    In MetadataWriter, it is possible that several CommitJobs for one photo are scheduled. If that happens, 
the callback will crash. This commit fixes this, by only allowing one job per photo. Canceled jobs are now 
kept in a separate list.

 src/MetadataWriter.vala |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/MetadataWriter.vala b/src/MetadataWriter.vala
index 969506e..9c60569 100644
--- a/src/MetadataWriter.vala
+++ b/src/MetadataWriter.vala
@@ -165,6 +165,7 @@ public class MetadataWriter : Object {
     private bool enabled = false;
     private HashTimedQueue<LibraryPhoto> dirty;
     private Gee.HashMap<LibraryPhoto, CommitJob> pending = new Gee.HashMap<LibraryPhoto, CommitJob>();
+    private Gee.HashSet<CommitJob> pending_cancel = new Gee.HashSet<CommitJob>();
     private Gee.HashSet<string> interested_photo_details = new Gee.HashSet<string>();
     private LibraryPhoto? ignore_photo_alteration = null;
     private uint outstanding_total = 0;
@@ -578,7 +579,10 @@ public class MetadataWriter : Object {
         bool cancelled = false;
         
         if (pending.has_key(photo)) {
-            pending.get(photo).cancel();
+            CommitJob j = (CommitJob) pending.get(photo);
+            pending_cancel.add(j);
+            j.cancel();
+            pending.unset(photo);
             cancelled = true;
         }
         
@@ -610,6 +614,10 @@ public class MetadataWriter : Object {
                 keywords.add(tag.get_name());
         }
         
+        // check if there is already a job for that photo. if yes, cancel it.
+        if (pending.has_key(photo))
+            cancel_job(photo);
+
         CommitJob job = new CommitJob(this, photo, keywords);
         pending.set(photo, job);
         
@@ -683,7 +691,7 @@ public class MetadataWriter : Object {
     }
     
     private void on_update_cancelled(BackgroundJob j) {
-        bool removed = pending.unset(((CommitJob) j).photo);
+        bool removed = pending_cancel.remove((CommitJob) j);
         assert(removed);
         
         count_cancelled_work(1, true);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]