[rygel] media-export: Don't delete file from fs event



commit 75d644a51c3d05c0867b5d5ed600f7c98a7629ac
Author: Jens Georg <mail jensge org>
Date:   Sun Aug 24 09:28:53 2014 +0200

    media-export: Don't delete file from fs event
    
    If a file is removed by the user, then don't try to remove the file
    again. There are some tools that move by remove & copy and Rygel will
    then remove the just copied file.
    
    Signed-off-by: Jens Georg <mail jensge org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734303

 .../media-export/rygel-media-export-harvester.vala |   17 +++++++++++++----
 .../rygel-media-export-writable-db-container.vala  |   10 ++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala 
b/src/plugins/media-export/rygel-media-export-harvester.vala
index 0b8b1db..9cc1cc1 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -210,14 +210,23 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
             // change
             var id = MediaCache.get_id (file);
             var object = cache.get_object (id);
-            var parent = null as MediaContainer;
 
-            if (object != null) {
-                parent = object.parent;
-                if (parent is TrackableContainer) {
+            if (object != null && object.parent != null) {
+                var parent = object.parent;
+
+                if (parent is WritableDbContainer) {
+                    var container = parent as WritableDbContainer;
+
+                    container.remove_tracked (object);
+                } else if (parent is TrackableDbContainer) {
+                    // This should not be possible, but just to be sure.
                     var container = parent as TrackableContainer;
+
                     container.remove_child_tracked.begin (object);
                 }
+            } else {
+                warning (_("Could not find object %s or its parent. Database is inconsistent"),
+                         id);
             }
         } catch (Error error) {
             warning (_("Error removing object from database: %s"),
diff --git a/src/plugins/media-export/rygel-media-export-writable-db-container.vala 
b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
index d027fc8..cae8745 100644
--- a/src/plugins/media-export/rygel-media-export-writable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
@@ -127,4 +127,14 @@ internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
         yield this.remove_item (id, cancellable);
     }
 
+    public void remove_tracked (MediaObject object) throws Error {
+        this.updated (object, ObjectEventType.DELETED);
+        this.total_deleted_child_count++;
+
+        this.media_db.remove_by_id (object.id);
+
+        this.updated ();
+        this.child_removed (object);
+    }
+
 }


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