Skip to content

Commit

Permalink
don't traverse excluded folders to avoid PathTooLongException #156
Browse files Browse the repository at this point in the history
  • Loading branch information
superyyrrzz committed May 6, 2016
1 parent 22429a0 commit 22dcba0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/Microsoft.DocAsCode.Glob/FileGlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,11 @@ private static IEnumerable<string> GetFilesFromSubfolder(string baseDirectory, s
foreach (var dir in Directory.GetDirectories(baseDirectory, "*", SearchOption.TopDirectoryOnly))
{
var relativePath = GetRelativeDirectoryPath(cwd, dir);

// For folder, exclude glob matches folder means nothing, e.g. **/a matches b/a folder, however, **/a does not match b/a/c file
foreach (var glob in globs)
if (IsDirectoryMatch(relativePath, globs, excludeGlobs))
{
if (glob.Match(relativePath, true))
foreach (var file in GetFilesFromSubfolder(dir, cwd, globs, excludeGlobs))
{
foreach(var file in GetFilesFromSubfolder(dir, cwd, globs, excludeGlobs))
{
yield return file;
}

break;
yield return file;
}
}
}
Expand All @@ -84,14 +77,24 @@ private static string NormalizeToFullPath(string path)
}

private static bool IsFileMatch(string path, IEnumerable<GlobMatcher> globs, IEnumerable<GlobMatcher> excludeGlobs)
{
return IsMatch(path, globs, excludeGlobs, false);
}

private static bool IsDirectoryMatch(string path, IEnumerable<GlobMatcher> globs, IEnumerable<GlobMatcher> excludeGlobs)
{
return IsMatch(path, globs, excludeGlobs, true);
}

private static bool IsMatch(string path, IEnumerable<GlobMatcher> globs, IEnumerable<GlobMatcher> excludeGlobs, bool partial)
{
foreach (var exclude in excludeGlobs)
{
if (exclude.Match(path, false)) return false;
}
foreach (var glob in globs)
{
if (glob.Match(path, false)) return true;
if (glob.Match(path, partial)) return true;
}
return false;
}
Expand Down

0 comments on commit 22dcba0

Please sign in to comment.