[rygel] media-export: Fix endless loop



commit c6e60de0017153e60a42b3f5be94c8f472b28bef
Author: Jens Georg <mail jensge org>
Date:   Fri Jan 20 22:16:45 2012 +0100

    media-export: Fix endless loop
    
    If a file is added in a directory tree that didn't contain anything
    sharable before, the code would loop endlessly marching up the
    filesystem hierarchy.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668335

 .../media-export/rygel-media-export-harvester.vala |   25 ++++++++++++++++++-
 .../rygel-media-export-root-container.vala         |   13 ++++-----
 2 files changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index 68476b9..db9d80d 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -33,13 +33,24 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
     private Regex file_filter;
     private Cancellable cancellable;
 
+    // Properties
+    public ArrayList<File> locations { get; private set; }
+
     public signal void done ();
 
     /**
      * Create a new instance of the meta-data extraction manager.
      */
-    public Harvester (Cancellable cancellable) {
+    public Harvester (Cancellable     cancellable,
+                      ArrayList<File> locations) {
         this.cancellable = cancellable;
+        this.locations = new ArrayList<File> ((EqualFunc) File.equal);
+        foreach (var file in locations) {
+            if (file.query_exists ()) {
+                this.locations.add (file);
+            }
+        }
+
         this.extractor = new MetadataExtractor ();
 
         this.monitor = new RecursiveFileMonitor (cancellable);
@@ -178,10 +189,20 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
                         var parent = current.get_parent ();
                         id = MediaCache.get_id (parent);
                         parent_container = cache.get_object (id)
-                            as MediaContainer;
+                                        as MediaContainer;
+
                         if (parent_container == null) {
                             current = parent;
                         }
+
+                        if (current in this.locations) {
+                            // We have reached the top
+                            parent_container = cache.get_object
+                                        (RootContainer.FILESYSTEM_FOLDER_ID)
+                                        as MediaContainer;
+
+                            break;
+                        }
                     } while (parent_container == null);
 
                     this.schedule (current, parent_container);
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index 0b00078..2bd2fd9 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -348,7 +348,6 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
         base (db, "0", _("@REALNAME@'s media"));
 
         this.cancellable = new Cancellable ();
-        this.harvester = new Harvester (this.cancellable);
 
         try {
             this.service = new DBusService (this);
@@ -377,15 +376,15 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
             ids = new ArrayList<string> ();
         }
 
+        this.harvester = new Harvester (this.cancellable,
+                                        this.get_shared_uris ());
         this.harvester_signal_id = this.harvester.done.connect
                                         (on_initial_harvesting_done);
 
-        foreach (var file in this.get_shared_uris ()) {
-            if (file.query_exists (null)) {
-                ids.remove (MediaCache.get_id (file));
-                this.harvester.schedule (file,
-                                         this.filesystem_container);
-            }
+        foreach (var file in this.harvester.locations) {
+            ids.remove (MediaCache.get_id (file));
+            this.harvester.schedule (file,
+                                     this.filesystem_container);
         }
 
         foreach (var id in ids) {



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