Exemplo n.º 1
0
            internal void DoGlob(string /*!*/ baseDirectory, int position, bool isPreviousDoubleStar)
            {
                if (!_pal.DirectoryExists(baseDirectory))
                {
                    return;
                }

                bool   containsWildcard;
                int    patternEnd        = FindNextSeparator(position, true, out containsWildcard);
                bool   isLastPathSegment = (patternEnd == _pattern.Length);
                string dirSegment        = _pattern.Substring(position, patternEnd - position);

                if (!isLastPathSegment)
                {
                    patternEnd++;
                }

                if (!containsWildcard)
                {
                    string path = baseDirectory + "/" + dirSegment;
                    TestPath(path, patternEnd, isLastPathSegment);
                    return;
                }

                bool doubleStar = dirSegment.Equals("**");

                if (doubleStar && !isPreviousDoubleStar)
                {
                    DoGlob(baseDirectory, patternEnd, true);
                }

                foreach (string file in _pal.GetFileSystemEntries(baseDirectory, "*"))
                {
                    string objectName = Path.GetFileName(file);
                    if (FnMatch(dirSegment, objectName, _flags))
                    {
                        var canon = RubyUtils.CanonicalizePath(file);
                        TestPath(canon, patternEnd, isLastPathSegment);
                        if (doubleStar)
                        {
                            DoGlob(canon, position, true);
                        }
                    }
                }
                if (isLastPathSegment && (_flags & Constants.FNM_DOTMATCH) != 0 || dirSegment[0] == '.')
                {
                    if (FnMatch(dirSegment, ".", _flags))
                    {
                        string directory = baseDirectory + "/.";
                        if (_dirOnly)
                        {
                            directory += '/';
                        }
                        TestPath(directory, patternEnd, true);
                    }
                    if (FnMatch(dirSegment, "..", _flags))
                    {
                        string directory = baseDirectory + "/..";
                        if (_dirOnly)
                        {
                            directory += '/';
                        }
                        TestPath(directory, patternEnd, true);
                    }
                }
            }
Exemplo n.º 2
0
Arquivo: Glob.cs Projeto: legigor/Nake
            private void DoGlob(string baseDirectory, int position, bool isPreviousDoubleStar)
            {
                if (!pal.DirectoryExists(baseDirectory))
                {
                    return;
                }

                bool containsWildcard;
                var  patternEnd        = FindNextSeparator(position, true, out containsWildcard);
                var  isLastPathSegment = (patternEnd == pattern.Length);
                var  dirSegment        = pattern.Substring(position, patternEnd - position);

                if (!isLastPathSegment)
                {
                    patternEnd++;
                }

                if (!containsWildcard)
                {
                    var path = baseDirectory + "/" + dirSegment;
                    TestPath(path, patternEnd, isLastPathSegment);
                    return;
                }

                var doubleStar = dirSegment.Equals("**");

                if (doubleStar && !isPreviousDoubleStar)
                {
                    DoGlob(baseDirectory, patternEnd, true);
                }

                foreach (string file in pal.GetFileSystemEntries(baseDirectory, "*"))
                {
                    var objectName = Path.GetFileName(file);
                    if (FnMatch(dirSegment, objectName, flags))
                    {
                        var canon = file.Replace('\\', '/');
                        TestPath(canon, patternEnd, isLastPathSegment);
                        if (doubleStar)
                        {
                            DoGlob(canon, position, true);
                        }
                    }
                }
                if ((!isLastPathSegment || (flags & Constants.DotMatch) == 0) && dirSegment[0] != '.')
                {
                    return;
                }
                if (FnMatch(dirSegment, ".", flags))
                {
                    var directory = baseDirectory + "/.";
                    if (dirOnly)
                    {
                        directory += '/';
                    }
                    TestPath(directory, patternEnd, true);
                }
                if (FnMatch(dirSegment, "..", flags))
                {
                    var directory = baseDirectory + "/..";
                    if (dirOnly)
                    {
                        directory += '/';
                    }
                    TestPath(directory, patternEnd, true);
                }
            }