[banshee] Migrate partial file paths by converting them to URIs



commit 00e46bc7f426a03118db34b81d0840730580a818
Author: John Millikin <jmillikin gmail com>
Date:   Sat Apr 25 15:23:52 2009 -0700

    Migrate partial file paths by converting them to URIs
---
 .../Banshee.Database/BansheeDbFormatMigrator.cs    |   28 ++++++++++++++++---
 1 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
index ad6fd25..1f59444 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
@@ -33,6 +33,7 @@ using System.Reflection;
 using System.Text;
 using System.Threading;
 using Mono.Unix;
+using Mono.Data.Sqlite;
 
 using Hyena;
 using Hyena.Jobs;
@@ -727,12 +728,17 @@ namespace Banshee.Database
                 string library_path = Banshee.Library.LibrarySource.OldLocationSchema.Get ();
                 if (library_path != null) {
                     int podcast_src_id = connection.Query<int> ("SELECT PrimarySourceID FROM CorePrimarySources WHERE StringID = 'PodcastSource-PodcastLibrary'");
-                    
-                    Banshee.Base.SafeUri uri = new Banshee.Base.SafeUri (library_path);
-                    connection.Execute ("UPDATE CoreTracks SET Uri = (? || Uri) WHERE UriType = 1 AND PrimarySourceID != ?", uri.AbsoluteUri + System.IO.Path.DirectorySeparatorChar, podcast_src_id);
 
-                    uri = new Banshee.Base.SafeUri (Banshee.Base.Paths.Combine (library_path, "Podcasts"));
-                    connection.Execute ("UPDATE CoreTracks SET Uri = (? || Uri) WHERE UriType = 1 AND PrimarySourceID = ?", uri.AbsoluteUri + System.IO.Path.DirectorySeparatorChar, podcast_src_id);
+                    connection.Execute (@"
+                        UPDATE CoreTracks SET Uri = BANSHEE_MIGRATE_PARTIAL(?, Uri)
+                        WHERE UriType = 1
+                          AND PrimarySourceID != ?", library_path, podcast_src_id);
+
+                    string podcast_path = Banshee.Base.Paths.Combine (library_path, "Podcasts");
+                    connection.Execute (@"
+                        UPDATE CoreTracks SET Uri = BANSHEE_MIGRATE_PARTIAL(?, Uri)
+                        WHERE UriType = 1
+                          AND PrimarySourceID = ?", podcast_path, podcast_src_id);
                 }
             } catch (Exception e) {
                 Hyena.Log.Exception (e);
@@ -1189,4 +1195,16 @@ namespace Banshee.Database
 #endregion
 
     }
+
+    [SqliteFunction (Name = "BANSHEE_MIGRATE_PARTIAL", FuncType = FunctionType.Scalar, Arguments = 2)]
+    internal class MigratePartialFunction : SqliteFunction
+    {
+        public override object Invoke (object[] args)
+        {
+            string library_path = (string)args[0];
+            string filename_fragment = (string)args[1];
+            string full_path = Banshee.Base.Paths.Combine (library_path, filename_fragment);
+            return Banshee.Base.SafeUri.FilenameToUri (full_path);
+        }
+    }
 }



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