[banshee] AppleDeviceSource: postpone the removal of invalid tracks to the sync cycle



commit f1fb1ca05cccf5d6d6c59c3a47197b33c7d6b2d9
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Sun Sep 23 16:24:17 2012 +0100

    AppleDeviceSource: postpone the removal of invalid tracks to the sync cycle
    
    The fix for bgo#634652 has caused a bit of trouble for other users:
    a) It caused bgo#679260, which was fixed in Banshee 2.5.0.
    b) It delayed the initialization of the device, as explained by a user
    in https://bugzilla.gnome.org/show_bug.cgi?id=679260#c25.
    
    To avoid b), we now postpone the removal of invalid tracks to the sync cycle.
    
    This way:
    - There is no delay in the load process.
    - No writing operations happen in the device until there is a need of a sync.
    
    In this commit we also wrap the deletion under a try-catch, to be super sure that
    the sync process can continue (in the same way it is done for the removal of non
    invalid tracks).

 .../Banshee.Dap.AppleDevice/AppleDeviceSource.cs   |   28 ++++++++++++++-----
 1 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
index 2b11f15..8b5fa1d 100644
--- a/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
+++ b/src/Dap/Banshee.Dap.AppleDevice/Banshee.Dap.AppleDevice/AppleDeviceSource.cs
@@ -209,11 +209,10 @@ namespace Banshee.Dap.AppleDevice
                 });
             }
 
-            var invalid_tracks = new List<GPod.Track> ();
             foreach (var ipod_track in MediaDatabase.Tracks) {
 
                 if (String.IsNullOrEmpty (ipod_track.IpodPath)) {
-                    invalid_tracks.Add (ipod_track);
+                    invalid_tracks_in_device.Enqueue (ipod_track);
                     continue;
                 }
 
@@ -228,13 +227,10 @@ namespace Banshee.Dap.AppleDevice
                     Log.Exception (e);
                 }
             }
-            if (invalid_tracks.Count > 0) {
-                Log.Warning (String.Format ("Found {0} invalid tracks on the device", invalid_tracks.Count));
-                foreach (var track in invalid_tracks) {
-                    DeleteTrack (track, false);
-                }
-            }
 
+            if (invalid_tracks_in_device.Count > 0) {
+                Log.Warning (String.Format ("Found {0} invalid tracks on the device", invalid_tracks_in_device.Count));
+            }
 
             Hyena.Data.Sqlite.HyenaSqliteCommand insert_cmd = new Hyena.Data.Sqlite.HyenaSqliteCommand (
                 @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
@@ -385,6 +381,7 @@ namespace Banshee.Dap.AppleDevice
         private Queue<AppleDeviceTrackInfo> tracks_to_add = new Queue<AppleDeviceTrackInfo> ();
         private Queue<AppleDeviceTrackInfo> tracks_to_update = new Queue<AppleDeviceTrackInfo> ();
         private Queue<AppleDeviceTrackInfo> tracks_to_remove = new Queue<AppleDeviceTrackInfo> ();
+        private Queue<GPod.Track> invalid_tracks_in_device = new Queue<GPod.Track> ();
 
         private uint sync_timeout_id = 0;
         private object sync_timeout_mutex = new object ();
@@ -656,6 +653,21 @@ namespace Banshee.Dap.AppleDevice
                     Log.Exception ("Cannot remove track from iPod", e);
                 }
             }
+
+            SyncRemovalOfInvalidTracks ();
+        }
+
+        void SyncRemovalOfInvalidTracks ()
+        {
+            if (invalid_tracks_in_device.Count > 0) {
+                foreach (var track in invalid_tracks_in_device) {
+                    try {
+                        DeleteTrack (track, false);
+                    } catch (Exception e) {
+                        Log.Exception ("Cannot remove invalid track from iPod", e);
+                    }
+                }
+            }
         }
 
         void SyncTracksToPlaylists ()



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