Bug 5512 - System.IO.Directory.EnumerateDirectories fails to list all directories if CWD changes
Summary: System.IO.Directory.EnumerateDirectories fails to list all directories if CWD...
Status: NEEDINFO
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-06-04 16:24 UTC by Elisée Maurer
Modified: 2012-06-15 10:09 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Elisée Maurer 2012-06-04 16:24:28 UTC
Mono's System.IO.Directory.EnumerateDirectories doesn't list all directories in the specified (relative) path if the CWD changes during enumeration.

My guess is that the .NET version of System.IO.Directory.EnumerateDirectories() keeps a handle to the current working directory or maybe resolves the full path when called and Mono's version fails to do so, which makes it unable to keep enumerating directories if the CWD changes during enumeration.

I encountered this bug with the following code under Linux running Mono 2.10.:

  foreach( string strProjectDirectory in Directory.EnumerateDirectories( "Projects" ) )
  {
    // This method call changes the current working directory at some point
    DoSomethingWithProjectFolder( strProjectDirectory );

    // Other project folders never get enumerated
  }
Comment 1 Marek Safar 2012-06-15 10:09:42 UTC
I cannot reproduce the issue, my simple tests works

using System.IO;
using System;

class C
{
	public static void Main ()
	{
		foreach (var d in Directory.EnumerateDirectories ("/tmp/1", "*", SearchOption.AllDirectories))
		{
			Directory.SetCurrentDirectory ("/tmp");
			Console.WriteLine (d);
		}
	}
}

Note You need to log in before you can comment on or make changes to this bug.