public bool IsMatch()

in src/Artifacts/Tasks/RobocopyMetadata.cs [167:262]


        public bool IsMatch(string item, string subDirectory, bool isFile)
        {
            bool isMatch = false;
            bool isDeep = !string.IsNullOrEmpty(subDirectory);
            string deepDir = isDeep ? Path.Combine(SourceFolder, subDirectory) : SourceFolder;
            string deepItem = isDeep ? Path.Combine(subDirectory, item) : item;
            string rootedItem = Path.Combine(deepDir, item);

            if (isFile)
            {
                ++FilesSearched;
                if (isDeep)
                {
                    ++FilesSearchedRecursive;
                }

                if (DoMatchAll || FileMatches.Length == 0 && FileRegexMatches.Length == 0)
                {
                    isMatch = true;
                }
                else
                {
                    foreach (string match in FileMatches)
                    {
                        bool isRooted = Path.IsPathRooted(match);
                        if (isRooted && string.Equals(match, rootedItem, StringComparison.OrdinalIgnoreCase) ||
                           !isRooted && string.Equals(match, item, StringComparison.OrdinalIgnoreCase))
                        {
                            isMatch = true;
                            break;
                        }
                    }

                    if (!isMatch)
                    {
                        foreach (Regex match in FileRegexMatches)
                        {
                            // Allow for wildcard directories but not rooted ones
                            if (match.IsMatch(item) || isDeep && match.IsMatch(deepItem))
                            {
                                isMatch = true;
                                break;
                            }
                        }
                    }
                }

                foreach (string exclude in FileExcludes)
                {
                    bool isRooted = Path.IsPathRooted(exclude);
                    if (isRooted && rootedItem.Equals(exclude, StringComparison.OrdinalIgnoreCase) ||
                       !isRooted && item.Equals(exclude, StringComparison.OrdinalIgnoreCase))
                    {
                        return false;
                    }
                }

                foreach (Regex exclude in FileRegexExcludes)
                {
                    // Allow for wildcard directories but not rooted ones
                    if (exclude.IsMatch(item) || isDeep && exclude.IsMatch(deepItem))
                    {
                        return false;
                    }
                }

                ++FilesFound;
                if (isDeep)
                {
                    ++FilesFoundRecursive;
                }
            }
            else
            {
                isMatch = true;
                foreach (string exclude in DirExcludes)
                {
                    // Exclude directories with matching sub-directory
                    if (rootedItem.EndsWith(exclude, StringComparison.OrdinalIgnoreCase))
                    {
                        return false;
                    }
                }

                foreach (Regex exclude in DirRegexExcludes)
                {
                    // Allow for wildcard directories but not rooted ones
                    if (exclude.IsMatch(item) || isDeep && exclude.IsMatch(deepItem))
                    {
                        return false;
                    }
                }
            }

            return isMatch;
        }