[f-spot] Fix endless loops in import by ignoring symlinks.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Fix endless loops in import by ignoring symlinks.
- Date: Fri, 11 Jun 2010 17:13:31 +0000 (UTC)
commit 3ffc2e76058263e7de0c14d91c31f5bc6a83b151
Author: Ruben Vermeersch <ruben savanne be>
Date: Fri Jun 11 19:12:28 2010 +0200
Fix endless loops in import by ignoring symlinks.
https://bugzilla.gnome.org/show_bug.cgi?id=621156
src/Import/FileImportSource.cs | 6 ++++-
src/Utils/RecursiveFileEnumerator.cs | 39 ++++++++++++++++-----------------
2 files changed, 24 insertions(+), 21 deletions(-)
---
diff --git a/src/Import/FileImportSource.cs b/src/Import/FileImportSource.cs
index 23aa7c4..7eb8ee6 100644
--- a/src/Import/FileImportSource.cs
+++ b/src/Import/FileImportSource.cs
@@ -50,7 +50,11 @@ namespace FSpot.Import
protected void ScanPhotoDirectory (ImportController controller, SafeUri uri)
{
- var enumerator = new RecursiveFileEnumerator (uri, controller.RecurseSubdirectories, true);
+ var enumerator = new RecursiveFileEnumerator (uri) {
+ Recurse = controller.RecurseSubdirectories,
+ CatchNoPermission = true,
+ IgnoreSymlinks = true
+ };
var infos = new List<FileImportInfo> ();
foreach (var file in enumerator) {
if (ImageFile.HasLoader (new SafeUri (file.Uri, true))) {
diff --git a/src/Utils/RecursiveFileEnumerator.cs b/src/Utils/RecursiveFileEnumerator.cs
index cb47ad5..b2428b8 100644
--- a/src/Utils/RecursiveFileEnumerator.cs
+++ b/src/Utils/RecursiveFileEnumerator.cs
@@ -8,37 +8,34 @@ namespace FSpot.Utils
public class RecursiveFileEnumerator : IEnumerable<File>
{
string root;
- bool recurse;
- bool catch_no_permission;
- public RecursiveFileEnumerator (string root) : this (root, true, false)
- {
- }
-
- public RecursiveFileEnumerator (string root, bool recurse) : this (root, recurse, false)
- {
- }
+ public bool Recurse { get; set; }
+ public bool CatchNoPermission { get; set; }
+ public bool IgnoreSymlinks { get; set; }
- public RecursiveFileEnumerator (string root, bool recurse, bool catch_no_permission)
+ public RecursiveFileEnumerator (string root)
{
this.root = root;
- this.recurse = recurse;
- this.catch_no_permission = catch_no_permission;
+ this.Recurse = true;
+ this.CatchNoPermission = false;
+ this.IgnoreSymlinks = false;
}
IEnumerable<File> ScanForFiles (File root)
{
GLib.FileInfo root_info = null;
try {
- root_info = root.QueryInfo ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+ root_info = root.QueryInfo ("standard::name,standard::type,standard::is-symlink", FileQueryInfoFlags.None, null);
} catch (GLib.GException e) {
- if (!catch_no_permission)
+ if (!CatchNoPermission)
throw e;
yield break;
}
- using (root_info) {
- if (root_info.FileType == FileType.Regular) {
+ using (root_info) {
+ if (root_info.IsSymlink && IgnoreSymlinks) {
+ yield break;
+ } else if (root_info.FileType == FileType.Regular) {
yield return root;
} else if (root_info.FileType == FileType.Directory) {
foreach (var child in ScanDirectoryForFiles (root)) {
@@ -52,9 +49,9 @@ namespace FSpot.Utils
{
GLib.FileEnumerator enumerator = null;
try {
- enumerator = root_dir.EnumerateChildren ("standard::name,standard::type", FileQueryInfoFlags.None, null);
+ enumerator = root_dir.EnumerateChildren ("standard::name,standard::type,standard::is-symlink", FileQueryInfoFlags.None, null);
} catch (GLib.GException e) {
- if (!catch_no_permission)
+ if (!CatchNoPermission)
throw e;
yield break;
}
@@ -65,9 +62,11 @@ namespace FSpot.Utils
// The code below looks like a duplication of ScanForFiles
// (which could be invoked here instead), but doing so would
// lead to a double type query on files (using QueryInfo).
- if (info.FileType == FileType.Regular) {
+ if (info.IsSymlink && IgnoreSymlinks) {
+ continue;
+ } else if (info.FileType == FileType.Regular) {
yield return file;
- } else if (info.FileType == FileType.Directory && recurse) {
+ } else if (info.FileType == FileType.Directory && Recurse) {
foreach (var child in ScanDirectoryForFiles (file)) {
yield return child;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]