[banshee] Banshee.IO: Use strongly-typed SafeUri for GetFiles and GetDirectories
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Banshee.IO: Use strongly-typed SafeUri for GetFiles and GetDirectories
- Date: Tue, 21 Aug 2012 20:43:15 +0000 (UTC)
commit f6cbbb8c08c3098b844e2806ece1519375161b6e
Author: Andres G. Aragoneses <knocte gmail com>
Date: Sat Jul 7 13:17:02 2012 +0100
Banshee.IO: Use strongly-typed SafeUri for GetFiles and GetDirectories
Fix a FIXME that was placed in the Banshee.IO.IDirectory interface:
the files and directories returned by all backends should be returning
the same format of filesystem representation. By using SafeUri type,
we enforce this check at compile time.
Thanks to this refactoring, bugs like bgo#679252 are fixed and should
not happen again.
Signed-off-by: Bertrand Lorentz <bertrand lorentz gmail com>
.../Banshee.Gio/Banshee.IO.Gio/Directory.cs | 12 ++++++------
src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs | 4 ++--
.../Banshee.Unix/Banshee.IO.Unix/Directory.cs | 8 ++++----
.../Banshee.Core/Banshee.IO.SystemIO/Directory.cs | 11 +++++++----
src/Core/Banshee.Core/Banshee.IO/Directory.cs | 4 ++--
src/Core/Banshee.Core/Banshee.IO/IDirectory.cs | 5 ++---
src/Core/Banshee.Core/Banshee.IO/Tests.cs | 16 ++++------------
7 files changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
index 76563f7..9169e19 100644
--- a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
+++ b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Directory.cs
@@ -108,17 +108,17 @@ namespace Banshee.IO.Gio
return (type & FileType.Directory) != 0;
}
- public IEnumerable<string> GetFiles (string directory)
+ public IEnumerable<SafeUri> GetFiles (string directory)
{
return GetFiles (GetDir (directory), true);
}
- private IEnumerable<string> GetFiles (GLib.File dir, bool followSymlinks)
+ private IEnumerable<SafeUri> GetFiles (GLib.File dir, bool followSymlinks)
{
var enumerator = dir.EnumerateChildren ("standard::type,standard::name", followSymlinks ? FileQueryInfoFlags.None : FileQueryInfoFlags.NofollowSymlinks, null);
foreach (FileInfo file in enumerator) {
if ((file.FileType & FileType.Regular) != 0) {
- var ret = SafeUri.FilenameToUri (System.IO.Path.Combine (dir.Path, file.Name));
+ var ret = new SafeUri (System.IO.Path.Combine (dir.Path, file.Name), false);
file.Dispose ();
yield return ret;
} else {
@@ -131,17 +131,17 @@ namespace Banshee.IO.Gio
}
}
- public IEnumerable<string> GetDirectories (string directory)
+ public IEnumerable<SafeUri> GetDirectories (string directory)
{
return GetDirectories (GetDir (directory), true);
}
- private IEnumerable<string> GetDirectories (GLib.File dir, bool followSymlinks)
+ private IEnumerable<SafeUri> GetDirectories (GLib.File dir, bool followSymlinks)
{
var enumerator = dir.EnumerateChildren ("standard::type,standard::name", followSymlinks ? FileQueryInfoFlags.None : FileQueryInfoFlags.NofollowSymlinks, null);
foreach (FileInfo file in enumerator) {
if ((file.FileType & FileType.Directory) != 0) {
- var ret = SafeUri.FilenameToUri (System.IO.Path.Combine (dir.Path, file.Name));
+ var ret = new SafeUri (System.IO.Path.Combine (dir.Path, file.Name), false);
file.Dispose ();
yield return ret;
} else {
diff --git a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs
index 8391ac8..966c1c6 100644
--- a/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs
+++ b/src/Backends/Banshee.Gio/Banshee.IO.Gio/Tests.cs
@@ -241,14 +241,14 @@ namespace Banshee.IO.Gio
[Test]
public void GetChildFiles ()
{
- var files = dir.GetFiles (tmp_dir).ToArray ();
+ var files = dir.GetFiles (tmp_dir).Select (f => f.AbsoluteUri).ToArray ();
Assert.AreEqual (files, new string [] { foo.AbsoluteUri, baz.AbsoluteUri });
}
[Test]
public void GetChildDirs ()
{
- var dirs = dir.GetDirectories (tmp_dir).ToArray ();
+ var dirs = dir.GetDirectories (tmp_dir).Select (d => d.AbsoluteUri).ToArray ();
Assert.AreEqual (dirs, new string [] { new SafeUri (woo).AbsoluteUri });
}
diff --git a/src/Backends/Banshee.Unix/Banshee.IO.Unix/Directory.cs b/src/Backends/Banshee.Unix/Banshee.IO.Unix/Directory.cs
index fdca55e..7bb7333 100644
--- a/src/Backends/Banshee.Unix/Banshee.IO.Unix/Directory.cs
+++ b/src/Backends/Banshee.Unix/Banshee.IO.Unix/Directory.cs
@@ -86,7 +86,7 @@ namespace Banshee.IO.Unix
}
}
- public IEnumerable<string> GetFiles (string directory)
+ public IEnumerable<SafeUri> GetFiles (string directory)
{
var unix_dir = TraverseSymlink(new UnixDirectoryInfo (directory)) as UnixDirectoryInfo;
if (unix_dir == null) {
@@ -94,18 +94,18 @@ namespace Banshee.IO.Unix
}
foreach (var entry in unix_dir.GetFileSystemEntries ()) {
if (entry != null && !entry.IsDirectory && entry.IsRegularFile && !entry.IsSocket && entry.Exists) {
- yield return entry.FullName;
+ yield return new SafeUri (entry.FullName, false);
}
}
}
- public IEnumerable<string> GetDirectories (string directory)
+ public IEnumerable<SafeUri> GetDirectories (string directory)
{
var unix_dir = new UnixDirectoryInfo (directory);
foreach (var entry in unix_dir.GetFileSystemEntries ()) {
var info = TraverseSymlink (entry);
if (info != null && info.IsDirectory && info.Exists && !info.IsSocket) {
- yield return info.FullName;
+ yield return new SafeUri (info.FullName, false);
}
}
}
diff --git a/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs b/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs
index 02a2e91..d981426 100644
--- a/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs
+++ b/src/Core/Banshee.Core/Banshee.IO.SystemIO/Directory.cs
@@ -27,6 +27,7 @@
//
using System;
+using System.Linq;
using System.Collections.Generic;
using Hyena;
@@ -55,14 +56,16 @@ namespace Banshee.IO.SystemIO
return System.IO.Directory.Exists (directory);
}
- public IEnumerable<string> GetFiles (string directory)
+ public IEnumerable<SafeUri> GetFiles (string directory)
{
- return System.IO.Directory.GetFiles (directory);
+ return System.IO.Directory.GetFiles (directory)
+ .Select (filePath => new SafeUri (filePath, false));
}
- public IEnumerable<string> GetDirectories (string directory)
+ public IEnumerable<SafeUri> GetDirectories (string directory)
{
- return System.IO.Directory.GetDirectories (directory);
+ return System.IO.Directory.GetDirectories (directory)
+ .Select (filePath => new SafeUri (filePath, false));
}
public void Move (SafeUri from, SafeUri to)
diff --git a/src/Core/Banshee.Core/Banshee.IO/Directory.cs b/src/Core/Banshee.Core/Banshee.IO/Directory.cs
index a44673a..ed098f0 100644
--- a/src/Core/Banshee.Core/Banshee.IO/Directory.cs
+++ b/src/Core/Banshee.Core/Banshee.IO/Directory.cs
@@ -63,12 +63,12 @@ namespace Banshee.IO
Provider.Directory.Delete (Provider.GetPath (directory), recursive);
}
- public static IEnumerable<string> GetFiles (string directory)
+ public static IEnumerable<SafeUri> GetFiles (string directory)
{
return Provider.Directory.GetFiles (Provider.GetPath (directory));
}
- public static IEnumerable<string> GetDirectories (string directory)
+ public static IEnumerable<SafeUri> GetDirectories (string directory)
{
return Provider.Directory.GetDirectories (Provider.GetPath (directory));
}
diff --git a/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs b/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs
index 5d14945..9f38637 100644
--- a/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs
+++ b/src/Core/Banshee.Core/Banshee.IO/IDirectory.cs
@@ -43,8 +43,7 @@ namespace Banshee.IO
void Delete (string directory);
void Delete (string directory, bool recursive);
- // FIXME: These probably need to normalize to SafeUri
- IEnumerable<string> GetFiles (string directory);
- IEnumerable<string> GetDirectories (string directory);
+ IEnumerable<SafeUri> GetFiles (string directory);
+ IEnumerable<SafeUri> GetDirectories (string directory);
}
}
diff --git a/src/Core/Banshee.Core/Banshee.IO/Tests.cs b/src/Core/Banshee.Core/Banshee.IO/Tests.cs
index fd1b657..240c00e 100644
--- a/src/Core/Banshee.Core/Banshee.IO/Tests.cs
+++ b/src/Core/Banshee.Core/Banshee.IO/Tests.cs
@@ -334,12 +334,8 @@ namespace Banshee.IO
public void GetChildFiles ()
{
ForEachProvider (() => {
- var files = Directory.GetFiles (tmp_dir).ToArray ();
- if (Provider.LocalOnly) {
- AssertContainsSameElements (new string [] { baz.LocalPath, foo.LocalPath }, files);
- } else {
- AssertContainsSameElements (new string [] { foo.AbsoluteUri, baz.AbsoluteUri }, files);
- }
+ var files = Directory.GetFiles (tmp_dir).Select (f => f.AbsoluteUri).ToArray ();
+ AssertContainsSameElements (new string [] { foo.AbsoluteUri, baz.AbsoluteUri }, files);
});
}
@@ -362,12 +358,8 @@ namespace Banshee.IO
public void GetChildDirs ()
{
ForEachProvider (() => {
- var dirs = Directory.GetDirectories (tmp_dir).ToArray ();
- if (Provider.LocalOnly) {
- Assert.AreEqual (new string [] { new SafeUri (woo).LocalPath }, dirs);
- } else {
- Assert.AreEqual (new string [] { new SafeUri (woo).AbsoluteUri }, dirs);
- }
+ var dirs = Directory.GetDirectories (tmp_dir).Select (d => d.AbsoluteUri).ToArray ();
+ Assert.AreEqual (new string [] { new SafeUri (woo).AbsoluteUri }, dirs);
});
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]