[f-spot] Allow skipping over files with no permission in RecursiveFileEnumerator.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Allow skipping over files with no permission in RecursiveFileEnumerator.
- Date: Thu, 20 May 2010 08:32:11 +0000 (UTC)
commit d7e3eb43ab8744e3f1834f29d4845762ab5ed610
Author: Ruben Vermeersch <ruben savanne be>
Date: Thu May 20 10:04:14 2010 +0200
Allow skipping over files with no permission in RecursiveFileEnumerator.
https://bugzilla.gnome.org/show_bug.cgi?id=619170
src/FileImportBackend.cs | 2 +-
src/Utils/RecursiveFileEnumerator.cs | 39 ++++++++++++++++++++++++++-------
2 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/src/FileImportBackend.cs b/src/FileImportBackend.cs
index 9e39bd1..e9338a2 100644
--- a/src/FileImportBackend.cs
+++ b/src/FileImportBackend.cs
@@ -69,7 +69,7 @@ public class FileImportBackend : ImportBackend {
import_info = new List<IBrowsableItem> ();
foreach (Uri uri in base_paths) {
- var enumerator = new RecursiveFileEnumerator (uri, recurse);
+ var enumerator = new RecursiveFileEnumerator (uri, recurse, true);
foreach (var file in enumerator) {
if (FSpot.ImageFile.HasLoader (file.Uri))
import_info.Add (new ImportInfo (file.Uri));
diff --git a/src/Utils/RecursiveFileEnumerator.cs b/src/Utils/RecursiveFileEnumerator.cs
index e41b908..cf2553a 100644
--- a/src/Utils/RecursiveFileEnumerator.cs
+++ b/src/Utils/RecursiveFileEnumerator.cs
@@ -8,21 +8,34 @@ namespace FSpot.Utils
public class RecursiveFileEnumerator : IEnumerable<File>
{
Uri root;
- bool recurse;
+ bool recurse;
+ bool catch_no_permission;
- public RecursiveFileEnumerator (Uri root) : this (root, true)
+ public RecursiveFileEnumerator (Uri root) : this (root, true, false)
{
}
- public RecursiveFileEnumerator (Uri root, bool recurse)
- {
- this.root = root;
- this.recurse = recurse;
- }
+ public RecursiveFileEnumerator (Uri root, bool recurse) : this (root, recurse, false)
+ {
+ }
+
+ public RecursiveFileEnumerator (Uri root, bool recurse, bool catch_no_permission)
+ {
+ this.root = root;
+ this.recurse = recurse;
+ this.catch_no_permission = catch_no_permission;
+ }
IEnumerable<File> ScanForFiles (File root)
{
- var root_info = root.QueryInfo ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+ GLib.FileInfo root_info = null;
+ try {
+ root_info = root.QueryInfo ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+ } catch (GLib.GException e) {
+ if (!catch_no_permission)
+ throw e;
+ yield break;
+ }
if (root_info.FileType == FileType.Regular) {
yield return root;
@@ -35,7 +48,15 @@ namespace FSpot.Utils
IEnumerable<File> ScanDirectoryForFiles (File root_dir)
{
- var enumerator = root_dir.EnumerateChildren ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+ GLib.FileEnumerator enumerator = null;
+ try {
+ enumerator = root_dir.EnumerateChildren ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+ } catch (GLib.GException e) {
+ if (!catch_no_permission)
+ throw e;
+ yield break;
+ }
+
foreach (FileInfo info in enumerator) {
File file = root_dir.GetChild (info.Name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]