[f-spot] Catch more errors in RecursiveFileEnumerator.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Catch more errors in RecursiveFileEnumerator.
- Date: Fri, 11 Jun 2010 17:32:33 +0000 (UTC)
commit db8c0bff8aab0d1140383f1beeeb5b89145fa6ce
Author: Ruben Vermeersch <ruben savanne be>
Date: Fri Jun 11 19:31:23 2010 +0200
Catch more errors in RecursiveFileEnumerator.
https://bugzilla.gnome.org/show_bug.cgi?id=620771
src/Import/FileImportSource.cs | 2 +-
src/Utils/RecursiveFileEnumerator.cs | 31 ++++++++++++++++++++++---------
2 files changed, 23 insertions(+), 10 deletions(-)
---
diff --git a/src/Import/FileImportSource.cs b/src/Import/FileImportSource.cs
index 7eb8ee6..4ee1942 100644
--- a/src/Import/FileImportSource.cs
+++ b/src/Import/FileImportSource.cs
@@ -52,7 +52,7 @@ namespace FSpot.Import
{
var enumerator = new RecursiveFileEnumerator (uri) {
Recurse = controller.RecurseSubdirectories,
- CatchNoPermission = true,
+ CatchErrors = true,
IgnoreSymlinks = true
};
var infos = new List<FileImportInfo> ();
diff --git a/src/Utils/RecursiveFileEnumerator.cs b/src/Utils/RecursiveFileEnumerator.cs
index b2428b8..654419b 100644
--- a/src/Utils/RecursiveFileEnumerator.cs
+++ b/src/Utils/RecursiveFileEnumerator.cs
@@ -10,24 +10,24 @@ namespace FSpot.Utils
string root;
public bool Recurse { get; set; }
- public bool CatchNoPermission { get; set; }
+ public bool CatchErrors { get; set; }
public bool IgnoreSymlinks { get; set; }
public RecursiveFileEnumerator (string root)
{
this.root = root;
this.Recurse = true;
- this.CatchNoPermission = false;
+ this.CatchErrors = false;
this.IgnoreSymlinks = false;
}
IEnumerable<File> ScanForFiles (File root)
{
- GLib.FileInfo root_info = null;
+ FileInfo root_info = null;
try {
root_info = root.QueryInfo ("standard::name,standard::type,standard::is-symlink", FileQueryInfoFlags.None, null);
- } catch (GLib.GException e) {
- if (!CatchNoPermission)
+ } catch (GException e) {
+ if (!CatchErrors)
throw e;
yield break;
}
@@ -47,16 +47,28 @@ namespace FSpot.Utils
IEnumerable<File> ScanDirectoryForFiles (File root_dir)
{
- GLib.FileEnumerator enumerator = null;
+ FileEnumerator enumerator = null;
try {
enumerator = root_dir.EnumerateChildren ("standard::name,standard::type,standard::is-symlink", FileQueryInfoFlags.None, null);
- } catch (GLib.GException e) {
- if (!CatchNoPermission)
+ } catch (GException e) {
+ if (!CatchErrors)
throw e;
yield break;
}
- foreach (FileInfo info in enumerator) {
+ while (true) {
+ FileInfo info = null;
+ try {
+ info = enumerator.NextFile ();
+ } catch (GException e) {
+ if (!CatchErrors)
+ throw e;
+ continue;
+ }
+
+ if (info == null)
+ break;
+
File file = root_dir.GetChild (info.Name);
// The code below looks like a duplication of ScanForFiles
@@ -73,6 +85,7 @@ namespace FSpot.Utils
}
info.Dispose ();
}
+
enumerator.Close (null);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]