[banshee] [Gio] Fix (and test) directory uri/path issues



commit f0d1e22a6433365ecf02a97999c67c69c69efbf9
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Jan 15 17:16:39 2010 -0800

    [Gio] Fix (and test) directory uri/path issues

 .../Banshee.Gio/Banshee.IO.Gio/Directory.cs        |   33 ++++++++------------
 src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs   |    8 +++-
 2 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
index 43ccbcd..ce37910 100644
--- a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
+++ b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
@@ -41,7 +41,7 @@ namespace Banshee.IO.Gio
     {
         public void Create (string directory)
         {
-            var file = FileFactory.NewForPath (directory);
+            var file = GetDir (directory);
             file.MakeDirectoryWithParents (null);
         }
 
@@ -52,15 +52,13 @@ namespace Banshee.IO.Gio
 
         public void Delete (string directory, bool recursive)
         {
-            Delete (directory, recursive, false);
+            Delete (directory, GetDir (directory), recursive);
         }
 
         internal static bool DisableNativeOptimizations = false;
 
-        private void Delete (string directory, bool recursive, bool directoryIsUri)
+        private void Delete (string directory, GLib.File dir, bool recursive)
         {
-            var dir = GetDir (directory, directoryIsUri);
-
             if (!dir.Exists) {
                 Console.WriteLine ("{0} doesn't exist", directory);
                 return;
@@ -83,21 +81,26 @@ namespace Banshee.IO.Gio
                 }
 
                 foreach (string child in GetDirectories (dir, false)) {
-                    Delete (child, true, true);
+                    Delete (child, GetDir (child, true), true);
                 }
             }
 
             dir.Delete ();
         }
 
-        private GLib.File GetDir (string directory, bool directoryIsUri)
+        private static GLib.File GetDir (string directory)
+        {
+            return GetDir (directory, directory.Contains ("://"));
+        }
+
+        private static GLib.File GetDir (string directory, bool directoryIsUri)
         {
             return directoryIsUri ? FileFactory.NewForUri (directory) : FileFactory.NewForPath (directory);
         }
 
         public bool Exists (string directory)
         {
-            var file = FileFactory.NewForPath (directory);
+            var file = GetDir (directory);
             if (!file.QueryExists (null))
                 return false;
 
@@ -107,12 +110,7 @@ namespace Banshee.IO.Gio
 
         public IEnumerable<string> GetFiles (string directory)
         {
-            return GetFiles (directory, true, false);
-        }
-
-        private IEnumerable<string> GetFiles (string directory, bool followSymlinks, bool directoryIsUri)
-        {
-            return GetFiles (GetDir (directory, directoryIsUri), followSymlinks);
+            return GetFiles (GetDir (directory), true);
         }
 
         private IEnumerable<string> GetFiles (GLib.File dir, bool followSymlinks)
@@ -126,12 +124,7 @@ namespace Banshee.IO.Gio
 
         public IEnumerable<string> GetDirectories (string directory)
         {
-            return GetDirectories (directory, true, false);
-        }
-
-        private IEnumerable<string> GetDirectories (string directory, bool followSymlinks, bool directoryIsUri)
-        {
-            return GetDirectories (GetDir (directory, directoryIsUri), followSymlinks);
+            return GetDirectories (GetDir (directory), true);
         }
 
         private IEnumerable<string> GetDirectories (GLib.File dir, bool followSymlinks)
diff --git a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs
index d5a573d..4345640 100644
--- a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs
+++ b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs
@@ -44,8 +44,8 @@ namespace Banshee.IO.Gio
         private File file = new File ();
         private Directory dir = new Directory ();
         private string tmp_dir = System.IO.Path.Combine (System.Environment.CurrentDirectory, "tmp-gio");
-        private SafeUri foo, baz;
-        private string woo;
+        private SafeUri foo, baz, zoo;
+        private string woo, yoo;
 
         static GioTests ()
         {
@@ -58,6 +58,8 @@ namespace Banshee.IO.Gio
             foo = Uri  ("foo");
             baz = Uri  ("baz");
             woo = Path ("woo");
+            zoo = new SafeUri ("file://" + Path ("foo"));
+            yoo = "file://" + tmp_dir;
 
             System.IO.Directory.CreateDirectory (tmp_dir);
             System.IO.File.WriteAllText (Path ("foo"), "bar");
@@ -78,8 +80,10 @@ namespace Banshee.IO.Gio
         public void Exists ()
         {
             Assert.IsTrue (file.Exists (foo));
+            Assert.IsTrue (file.Exists (zoo));
             Assert.IsTrue (file.Exists (baz));
             Assert.IsTrue ( dir.Exists (woo));
+            Assert.IsTrue ( dir.Exists (yoo));
         }
 
         [Test]



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