[corlib] Enumerate all subdirectories including the first one. Fixes #22857
authorMarek Safar <marek.safar@gmail.com>
Thu, 11 Sep 2014 09:20:44 +0000 (11:20 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 11 Sep 2014 09:20:44 +0000 (11:20 +0200)
mcs/class/corlib/System.IO/DirectoryInfo.cs
mcs/class/corlib/Test/System.IO/DirectoryInfoTest.cs

index ce558743516117060aec9c27bc44a691bcf3f713..09ed552f62e2322351a52ff6966f805c3248b033 100644 (file)
@@ -6,10 +6,12 @@
 //   Jim Richardson, develop@wtfo-guru.com
 //   Dan Lewis, dihlewis@yahoo.co.uk
 //   Sebastien Pouliot  <sebastien@ximian.com>
+//   Marek Safar  <marek.safar@gmail.com>
 //
 // Copyright (C) 2002 Ximian, Inc.
 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2014 Xamarin, Inc (http://www.xamarin.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -441,25 +443,19 @@ namespace System.IO {
                                throw MonoIO.GetException (Path.GetDirectoryName (path_with_pattern), (MonoIOError) error);
 
                        try {
-                               if (((rattr & FileAttributes.ReparsePoint) == 0)){
-                                       if ((rattr & FileAttributes.Directory) != 0)
-                                               yield return new DirectoryInfo (s);
-                                       else
-                                               yield return new FileInfo (s);
-                               }
-                               
-                               while ((s = MonoIO.FindNext (handle, out rattr, out error)) != null){
-                                       if ((rattr & FileAttributes.ReparsePoint) != 0)
-                                               continue;
-                                       if ((rattr & FileAttributes.Directory) != 0)
-                                               yield return new DirectoryInfo (s);
-                                       else
-                                               yield return new FileInfo (s);
-                                       
+                               do {
+                                       if (((rattr & FileAttributes.ReparsePoint) == 0)){
+                                               if ((rattr & FileAttributes.Directory) != 0)
+                                                       yield return new DirectoryInfo (s);
+                                               else
+                                                       yield return new FileInfo (s);
+                                       }
+
                                        if (((rattr & FileAttributes.Directory) != 0) && subdirs)
                                                foreach (FileSystemInfo child in EnumerateFileSystemInfos (s, searchPattern, searchOption))
                                                        yield return child;
-                               }
+
+                               } while ((s = MonoIO.FindNext (handle, out rattr, out error)) != null);
                        } finally {
                                MonoIO.FindClose (handle);
                        }
index cbb58727eb4aa7308d307af536851de0aa4170dc..3e34c81352ac4a0c241ef2cac0ecf1bf4c6f84d4 100644 (file)
@@ -10,6 +10,7 @@
 
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using System.Runtime.Serialization;
 using System.Runtime.Serialization.Formatters.Binary;
@@ -1059,6 +1060,23 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (TempFolder + DSC + "ToString.Test", info.ToString ());
                }
 
+#if NET_4_0
+               [Test]
+               public void EnumerateFileSystemInfosTest ()
+               {
+                       var dirInfo = new DirectoryInfo (TempFolder);
+                       dirInfo.CreateSubdirectory ("1").CreateSubdirectory ("a");
+                       dirInfo.CreateSubdirectory ("2").CreateSubdirectory ("b");
+
+                       var l = new List<string> ();
+                       foreach (var info in dirInfo.EnumerateFileSystemInfos ("*", SearchOption.AllDirectories))
+                               l.Add (info.Name);
+
+                       l.Sort ();
+                       Assert.AreEqual ("1,2,a,b", string.Join (",", l), "#1");
+               }
+#endif
+
 #if !MOBILE
                [Test]
                public void Serialization ()