banshee r4264 - in trunk/banshee: . src/Core/Banshee.Core/Banshee.Base src/Core/Banshee.Core/Banshee.Base/Tests src/Core/Banshee.Services/Banshee.Collection.Database



Author: gburt
Date: Sun Jul 27 22:45:29 2008
New Revision: 4264
URL: http://svn.gnome.org/viewvc/banshee?rev=4264&view=rev

Log:
2008-07-27  Gabriel Burt  <gabriel burt gmail com>

	Patches from Bertrand Lorentz fixing issues with files in folders whose
	name start the same as the library folder.

	* src/Core/Banshee.Core/Banshee.Base/Paths.cs: Add
	CachedLibraryLocationWithSeparator property.  Fix MakePathRelative method
	to add a path seperator as needed (BGO #539511).

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	Use the new -WithSeparator property, fixing copy-on-import (BGO #533177).

	* src/Core/Banshee.Core/Banshee.Base/Tests/FileNamePatternTests.cs: Unit
	tests written by me to make sure MakePathRelative works how we expect it
	to.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs
   trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Tests/FileNamePatternTests.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs	Sun Jul 27 22:45:29 2008
@@ -114,12 +114,20 @@
                 return null;
             }
             
-            if (path.Length < to.Length + 1) {
+            if (path == to) {
+                return String.Empty;
+            }
+            
+            if (to[to.Length - 1] != Path.DirectorySeparatorChar) {
+                to = to + Path.DirectorySeparatorChar;
+            }
+            
+            if (path.Length < to.Length) {
                 return null;
             }
             
             return path.StartsWith (to)
-                ? path.Substring (to.Length + 1)
+                ? path.Substring (to.Length)
                 : null;
         }
         
@@ -172,6 +180,7 @@
         }
         
         private static string cached_library_location;
+        private static string cached_library_location_with_separator;
         public static string LibraryLocation {
              get {
                 string path = LibrarySchema.Location.Get (Paths.DefaultLibraryPath);
@@ -185,6 +194,7 @@
              
              set {
                 cached_library_location = value;
+                cached_library_location_with_separator = null;
                 LibrarySchema.Location.Set (cached_library_location); 
             }
         }
@@ -193,6 +203,15 @@
             get { return cached_library_location ?? LibraryLocation; }
         }
         
+        public static string CachedLibraryLocationWithSeparator {
+            get {
+                if (cached_library_location_with_separator == null) {
+                    cached_library_location_with_separator = CachedLibraryLocation + Path.DirectorySeparatorChar;
+                }
+                return cached_library_location_with_separator;
+            }
+        }
+        
         private static string installed_application_prefix = null;
         public static string InstalledApplicationPrefix {
             get {

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Tests/FileNamePatternTests.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Tests/FileNamePatternTests.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Tests/FileNamePatternTests.cs	Sun Jul 27 22:45:29 2008
@@ -44,6 +44,16 @@
             string str = Convert.ToString(num);
             return num < 10 ? "0" + str : str;
         }
+
+        [Test]
+        public void MakePathsRelative ()
+        {
+            Assert.AreEqual ("baz", Paths.MakePathRelative ("/foo/bar/baz", "/foo/bar"));
+            Assert.AreEqual ("baz", Paths.MakePathRelative ("/foo/bar/baz", "/foo/bar/"));
+            Assert.AreEqual ("",    Paths.MakePathRelative ("/foo/bar/baz", "/foo/bar/baz"));
+            Assert.AreEqual (null,  Paths.MakePathRelative ("/foo/bar/baz", "foo"));
+            Assert.AreEqual (null,  Paths.MakePathRelative ("/fo", "/foo"));
+        }
     
         [Test]
         public void CreateFromTrackInfo()

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	Sun Jul 27 22:45:29 2008
@@ -511,7 +511,7 @@
                 return;
             }
             
-            bool in_library = old_uri.AbsolutePath.StartsWith (Paths.CachedLibraryLocation);
+            bool in_library = old_uri.AbsolutePath.StartsWith (Paths.CachedLibraryLocationWithSeparator);
 
             if (!in_library && (LibrarySchema.CopyOnImport.Get () || force_copy)) {
                 string new_filename = FileNamePattern.BuildFull (this, Path.GetExtension (old_uri.ToString ()));



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