[gnome-disk-utility] GduDVDSupport: Nuke overlapping ranges.



commit 5bfa9ee9b3d3cbff682546ab1d45bf21a9d17e5d
Author: David Zeuthen <zeuthen gmail com>
Date:   Tue Mar 11 13:26:24 2014 -0700

    GduDVDSupport: Nuke overlapping ranges.
    
    This happens with some DVDs.
    
    Signed-off-by: David Zeuthen <zeuthen gmail com>

 src/disks/gdudvdsupport.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/src/disks/gdudvdsupport.c b/src/disks/gdudvdsupport.c
index 7e6ddba..748e828 100644
--- a/src/disks/gdudvdsupport.c
+++ b/src/disks/gdudvdsupport.c
@@ -131,6 +131,7 @@ gdu_dvd_support_new  (const gchar *device_file,
   GList *l;
   guint64 pos;
   GArray *a;
+  Range *prev_range;
 
   /* We use dlopen() to access libdvdcss since it's normally not
    * shipped (so we can't hard-depend on it) but it may be installed
@@ -244,6 +245,40 @@ gdu_dvd_support_new  (const gchar *device_file,
    * TODO: ensure ranges are not overlapping
    */
   scrambled_ranges = g_list_sort (scrambled_ranges, (GCompareFunc) range_compare_func);
+
+  /* Remove overlapping ranges */
+  prev_range = NULL;
+  l = scrambled_ranges;
+  while (l != NULL)
+    {
+      Range *range = l->data;
+      GList *next = l->next;
+
+      if (prev_range != NULL)
+        {
+          if (range->start >= prev_range->end)
+            {
+              prev_range = range;
+            }
+          else
+            {
+              if (G_UNLIKELY (support->debug))
+                {
+                  g_print ("Skipping overlapping range %" G_GUINT64_FORMAT " -> %" G_GUINT64_FORMAT " "
+                           "(Prev %" G_GUINT64_FORMAT " -> %" G_GUINT64_FORMAT ")\n",
+                           range->start, range->end, prev_range->start, prev_range->end);
+                }
+              scrambled_ranges = g_list_delete_link (scrambled_ranges, l);
+              g_free (range);
+            }
+        }
+      else
+        {
+          prev_range = range;
+        }
+      l = next;
+    }
+
   a = g_array_new (FALSE, /* zero-terminated */
                    FALSE, /* clear */
                    sizeof (Range));


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