media-export: Fix endless loop
authorJens Georg <mail@jensge.org>
Fri, 20 Jan 2012 21:16:45 +0000 (22:16 +0100)
committerJens Georg <mail@jensge.org>
Fri, 20 Jan 2012 21:20:01 +0000 (22:20 +0100)
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

src/plugins/media-export/rygel-media-export-harvester.vala
src/plugins/media-export/rygel-media-export-root-container.vala

index 68476b9..db9d80d 100644 (file)
@@ -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);
index 0b00078..2bd2fd9 100644 (file)
@@ -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) {