public bool IsMatch(string fileToMatch) { Debug.Assert(!string.IsNullOrEmpty(fileToMatch)); // We do the matching using one of three code paths, depending on the value of _filenamePattern and _regex. if (_regex != null) { string normalizedFileToMatch = FileUtilities.GetFullPathNoThrow(Path.Combine(_currentDirectory, fileToMatch)); return(_regex.IsMatch(normalizedFileToMatch)); } if (_filenamePattern != null) { // Check file name first as it's more likely to not match. string filename = Path.GetFileName(fileToMatch); if (!FileMatcher.IsMatch(filename, _filenamePattern)) { return(false); } var normalizedFileToMatch = FileUtilities.GetFullPathNoThrow(Path.Combine(_currentDirectory, fileToMatch)); return(normalizedFileToMatch.StartsWith(_currentDirectory, StringComparison.OrdinalIgnoreCase)); } return(FileUtilities.ComparePathsNoThrow(_unescapedFileSpec, fileToMatch, _currentDirectory, alwaysIgnoreCase: true)); }
private bool MetadataComparer(MatchOnMetadataOptions options, string itemMetadata, string referencedItemMetadata) { if (options.Equals(MatchOnMetadataOptions.PathLike)) { return(FileUtilities.ComparePathsNoThrow(itemMetadata, referencedItemMetadata, ProjectDirectory)); } else { return(String.Equals(itemMetadata, referencedItemMetadata, options.Equals(MatchOnMetadataOptions.CaseInsensitive) ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)); } }
public bool IsMatch(string fileToMatch) { Debug.Assert(!string.IsNullOrEmpty(fileToMatch)); // check if there is a regex matching the file if (_regex != null) { var normalizedFileToMatch = FileUtilities.GetFullPathNoThrow(Path.Combine(_currentDirectory, fileToMatch)); return(_regex.IsMatch(normalizedFileToMatch)); } return(FileUtilities.ComparePathsNoThrow(_unescapedFileSpec, fileToMatch, _currentDirectory)); }
internal static Func <string, bool> GetFileSpecMatchTester(string filespec, string currentDirectory) { Debug.Assert(!string.IsNullOrEmpty(filespec)); var unescapedSpec = EscapingUtilities.UnescapeAll(filespec); var regex = FilespecHasWildcards(filespec) ? CreateRegex(unescapedSpec, currentDirectory) : null; return(fileToMatch => { Debug.Assert(!string.IsNullOrEmpty(fileToMatch)); // check if there is a regex matching the file if (regex != null) { var normalizedFileToMatch = FileUtilities.GetFullPathNoThrow(Path.Combine(currentDirectory, fileToMatch)); return regex.IsMatch(normalizedFileToMatch); } return FileUtilities.ComparePathsNoThrow(unescapedSpec, fileToMatch, currentDirectory); }); }
internal static Func <string, bool> GetMatchTester(string filespec, string currentDirectory) { var unescapedSpec = EscapingUtilities.UnescapeAll(filespec); Regex regex = null; // TODO: assumption on file system case sensitivity: https://github.com/Microsoft/msbuild/issues/781 if (FilespecHasWildcards(filespec)) { Regex regexFileMatch; bool isRecursive; bool isLegal; // TODO: If creating Regex's here ends up being expensive perf-wise, consider how to avoid it in common cases FileMatcher.GetFileSpecInfo( unescapedSpec, out regexFileMatch, out isRecursive, out isLegal, FileMatcher.s_defaultGetFileSystemEntries); // If the spec is not legal, it doesn't match anything regex = isLegal ? regexFileMatch : null; } return(file => { var unescapedFile = EscapingUtilities.UnescapeAll(file); // check if there is a regex matching the file if (regex != null) { return regex.IsMatch(unescapedFile); } return FileUtilities.ComparePathsNoThrow(unescapedSpec, unescapedFile, currentDirectory); }); }
private bool IsMatch(string itemToMatch) { // todo file-system assumption on case sensitivity https://github.com/Microsoft/msbuild/issues/781 return(ItemSpecFragment.Equals(itemToMatch, StringComparison.OrdinalIgnoreCase) || FileUtilities.ComparePathsNoThrow(itemToMatch, ItemSpecFragment, _projectPath)); }