diff options
author | Rodrigo Kumpera <kumpera@gmail.com> | 2013-06-05 02:49:34 +0400 |
---|---|---|
committer | Rodrigo Kumpera <kumpera@gmail.com> | 2013-06-05 02:49:34 +0400 |
commit | d6fd0cde054da374b223d36f3c7696f4a197d131 (patch) | |
tree | 5260ee2eecb2f93015a605ff8370660dca58676d /mcs | |
parent | e16eacc268b72be7c7d930771822b03c460c11dd (diff) |
Make sure the behavior between GetFiles and EnumerateFiles are the same regarding symlinks. Fixes BXC #12461
* Directory.cs: Only ignore symlinks when traversing subdirectories. This is the only case that it can result
in loops.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/System.IO/Directory.cs | 5 | ||||
-rw-r--r-- | mcs/class/corlib/Test/System.IO/DirectoryTest.cs | 46 |
2 files changed, 48 insertions, 3 deletions
diff --git a/mcs/class/corlib/System.IO/Directory.cs b/mcs/class/corlib/System.IO/Directory.cs index 99586d35531..6066c031cba 100644 --- a/mcs/class/corlib/System.IO/Directory.cs +++ b/mcs/class/corlib/System.IO/Directory.cs @@ -537,7 +537,6 @@ namespace System.IO IntPtr handle; MonoIOError error; FileAttributes rattr; - string s = MonoIO.FindFirst (path, path_with_pattern, out rattr, out error, out handle); try { while (s != null) { @@ -545,7 +544,7 @@ namespace System.IO if (((rattr & FileAttributes.Directory) == 0) && rattr != 0) rattr |= FileAttributes.Normal; - if ((rattr & FileAttributes.ReparsePoint) == 0 && (rattr & kind) != 0) + if ((rattr & kind) != 0) yield return s; s = MonoIO.FindNext (handle, out rattr, out error); @@ -563,7 +562,7 @@ namespace System.IO try { while (s != null) { - if ((rattr & FileAttributes.Directory) != 0) + if ((rattr & FileAttributes.Directory) != 0 && (rattr & FileAttributes.ReparsePoint) == 0) foreach (string child in EnumerateKind (s, searchPattern, searchOption, kind)) yield return child; s = MonoIO.FindNext (handle, out rattr, out error); diff --git a/mcs/class/corlib/Test/System.IO/DirectoryTest.cs b/mcs/class/corlib/Test/System.IO/DirectoryTest.cs index 716a0139002..0692a876b75 100644 --- a/mcs/class/corlib/Test/System.IO/DirectoryTest.cs +++ b/mcs/class/corlib/Test/System.IO/DirectoryTest.cs @@ -10,12 +10,15 @@ //
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
+using System.IO;
using System.Text;
using System.Threading;
+using Mono.Unix;
using NUnit.Framework;
namespace MonoTests.System.IO
@@ -44,6 +47,49 @@ public class DirectoryTest Directory.Delete (TempFolder, true);
}
+ [Test] //BXC #12461
+ public void EnumerateFilesListSymlinks ()
+ {
+ if (!RunningOnUnix)
+ return;
+
+ var afile = Path.Combine (TempFolder, "afile.src");
+ var bfile = Path.Combine (TempFolder, "bfile.src");
+ var cdir = Path.Combine (TempFolder, "cdir.src");
+
+ File.AppendAllText (afile, "hello");
+ var info = new UnixFileInfo (afile);
+ info.CreateSymbolicLink (bfile);
+ Directory.CreateDirectory (cdir);
+
+ var files0 = Directory.GetFiles (TempFolder, "*.src");
+ Array.Sort (files0);
+ Assert.AreEqual (2, files0.Length, "#1");
+ Assert.AreEqual (afile, files0 [0], "#2");
+ Assert.AreEqual (bfile, files0 [1], "#3");
+
+ var files1 = new List<string> (Directory.EnumerateFiles (TempFolder, "*.src")).ToArray ();
+ Array.Sort (files1);
+ Assert.AreEqual (2, files1.Length, "#1.b");
+ Assert.AreEqual (afile, files1 [0], "#2.b");
+ Assert.AreEqual (bfile, files1 [1], "#3.b");
+
+ var files2 = Directory.GetFileSystemEntries (TempFolder, "*.src");
+ Array.Sort (files2);
+ Assert.AreEqual (3, files2.Length, "#1.c");
+ Assert.AreEqual (afile, files2 [0], "#2.c");
+ Assert.AreEqual (bfile, files2 [1], "#3.c");
+ Assert.AreEqual (cdir, files2 [2], "#4.c");
+
+ var files3 = new List<string> (Directory.EnumerateFileSystemEntries (TempFolder, "*.src")).ToArray ();
+ Array.Sort (files3);
+ Assert.AreEqual (3, files3.Length, "#1.d");
+ Assert.AreEqual (afile, files3 [0], "#2.d");
+ Assert.AreEqual (bfile, files3 [1], "#3.d");
+ Assert.AreEqual (cdir, files3 [2], "#4.d");
+
+ }
+
[Test]
public void CreateDirectory ()
{
|