Skip to content

Commit

Permalink
Introduce IsAllFilesWildcard() and call it from MatchFileRecursionStep
Browse files Browse the repository at this point in the history
  • Loading branch information
ladipro committed Jun 7, 2021
1 parent f475f2a commit 6bd221d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Shared/FileMatcher.cs
Expand Up @@ -131,7 +131,7 @@ internal FileMatcher(IFileSystem fileSystem, GetFileSystemEntries getFileSystemE
"*",
directory,
false));
IEnumerable<string> filteredEntriesForPath = (pattern != null && pattern != "*" && pattern != "*.*")
IEnumerable<string> filteredEntriesForPath = (pattern != null && !IsAllFilesWildcard(pattern))
? allEntriesForPath.Where(o => IsMatch(Path.GetFileName(o), pattern))
: allEntriesForPath;
return stripProjectDirectory
Expand Down Expand Up @@ -886,7 +886,7 @@ struct RecursionState
// The wildcard path portion of the excluded search matches the include search
searchToExclude.RemainingWildcardDirectory == recursionState.RemainingWildcardDirectory &&
// The exclude search will match ALL filenames OR
(searchToExclude.SearchData.Filespec == "*" || searchToExclude.SearchData.Filespec == "*.*" ||
(IsAllFilesWildcard(searchToExclude.SearchData.Filespec) ||
// The exclude search filename pattern matches the include search's pattern
searchToExclude.SearchData.Filespec == recursionState.SearchData.Filespec))
{
Expand Down Expand Up @@ -1091,7 +1091,11 @@ struct RecursionState

private static bool MatchFileRecursionStep(RecursionState recursionState, string file)
{
if (recursionState.SearchData.Filespec != null)
if (IsAllFilesWildcard(recursionState.SearchData.Filespec))
{
return true;
}
else if (recursionState.SearchData.Filespec != null)
{
return IsMatch(Path.GetFileName(file), recursionState.SearchData.Filespec);
}
Expand Down Expand Up @@ -2564,6 +2568,17 @@ private static bool DirectoryEndsWithPattern(string directoryPath, string patter
return (index != -1 && IsMatch(directoryPath.Substring(index + 1), pattern));
}

/// <summary>
/// Returns true if <paramref name="pattern"/> is <code>*</code> or <code>*.*</code>.
/// </summary>
/// <param name="pattern">The filename pattern to check.</param>
private static bool IsAllFilesWildcard(string pattern) => pattern?.Length switch
{
1 => pattern[0] == '*',
3 => pattern[0] == '*' && pattern[1] == '.' && pattern[2] == '*',
_ => false
};

internal static bool IsRecursiveDirectoryMatch(string path) => path.TrimTrailingSlashes() == recursiveDirectoryMatch;
}
}

0 comments on commit 6bd221d

Please sign in to comment.