kthompson/glob

Delete foreach Glob.Directories() fails

Closed this issue · 6 comments

Hi,

On version 1.1.1 this code

foreach (var dir in Glob.Directories(sourcePath, "**/bin")) {
    Directory.Delete(sourcePath + dir, true);
}

causes error

System.IO.DirectoryNotFoundException: Could not find a part of the path '...'.

Is this by design or bug?

Here is stacktrace:

   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
   at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerableFactory.DirectoryInfos(String directory, String expression, EnumerationOptions options)
   at System.IO.DirectoryInfo.InternalEnumerateInfos(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.DirectoryInfo.GetDirectories(String searchPattern, EnumerationOptions enumerationOptions)
   at System.IO.DirectoryInfo.GetDirectories()
   at GlobExpressions.TraverseOptions.GetDirectories(DirectoryInfo root)
   at GlobExpressions.PathTraverser.Traverse(DirectoryInfo root, Segment[] segments, Int32 segmentIndex, TraverseOptions options)
   at GlobExpressions.PathTraverser.Traverse(DirectoryInfo root, Segment[] segments, Int32 segmentIndex, TraverseOptions options)
   at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at ConsoleApp1.Program.Main(String[] args)

Did it literally say Could not find a part of the path '...'. or was there a specific path it was unable to find?

I want to add that calling ToList before iteration fixes it.

Oh I see, the files being iterated are being simultaneously deleted. Let me look at reproducing.

A prerelease version is available here that should fix the issue.

https://www.nuget.org/packages/Glob/1.1.2-CI-20190306-040219

Please let me know the results and I will push a 1.1.2 release.

Yes. This fix works.

Closed by 1.1.2. Thank you