private bool PathIsExcluded(FullPath path)
        {
            var project = _projectDiscovery.GetProject(path);
              if (project == null)
            return true;

              var rootPath = project.RootPath;

              // If path is root itself, it is never excluded.
              if (rootPath.Value.Length == path.Value.Length)
            return false;

              var rootLength = rootPath.Value.Length + 1; // Move past '\\' character.
              if (rootPath.Value.Last() == Path.DirectorySeparatorChar)
            rootLength--;

              var relativePath = path.Value.Substring(rootLength);
              var items = relativePath.Split(new char[] {
            Path.DirectorySeparatorChar
              });
              var pathToItem = new RelativePath();
              foreach (var item in items) {
            var relativePathToItem = pathToItem.CreateChild(item);

            if (!project.DirectoryFilter.Include(relativePathToItem))
              return true;

            // For the last component, we don't know if it is a file or directory.
            // Be conservative and try both.
            if (item == items.Last()) {
              if (!project.FileFilter.Include(relativePathToItem))
            return true;
            }

            pathToItem = relativePathToItem;
              }
              return false;
        }
        private bool PathIsExcluded(PathChangeEntry change)
        {
            var path    = change.Path;
            var project = _projectDiscovery.GetProject(path);

            if (project == null)
            {
                return(true);
            }

            // If path is root itself, it is never excluded.
            if (path == project.RootPath)
            {
                return(false);
            }

            // Split relative part into list of name components.
            var split        = PathHelpers.SplitPrefix(path.Value, project.RootPath.Value);
            var relativePath = split.Suffix;
            var names        = relativePath.Split(Path.DirectorySeparatorChar);

            // Check each relative path from root path to full path.
            var pathToItem = new RelativePath();

            foreach (var item in names)
            {
                var relativePathToItem = pathToItem.CreateChild(item);

                bool exclude;
                // For the last component, we might not if it is a file or directory.
                // Check depending on the change kind.
                if (item == names.Last())
                {
                    if (change.Kind == PathChangeKind.Deleted)
                    {
                        exclude = false;
                    }
                    else
                    {
                        var info = _fileSystem.GetFileInfoSnapshot(path);
                        if (info.IsFile)
                        {
                            exclude = !project.FileFilter.Include(relativePathToItem);
                        }
                        else if (info.IsDirectory)
                        {
                            exclude = !project.DirectoryFilter.Include(relativePathToItem);
                        }
                        else
                        {
                            // We don't know... Be conservative.
                            exclude = false;
                        }
                    }
                }
                else
                {
                    exclude = !project.DirectoryFilter.Include(relativePathToItem);
                }

                if (exclude)
                {
                    return(true);
                }

                pathToItem = relativePathToItem;
            }
            return(false);
        }
Esempio n. 3
0
        private bool PathIsExcluded(PathChangeEntry change)
        {
            // If path is root itself, it is never excluded.
            if (change.RelativePath.IsEmpty)
            {
                return(false);
            }

            var project = _projectDiscovery.GetProject(change.BasePath);

            if (project == null)
            {
                return(true);
            }

            // Split relative part into list of name components.
            var names = PathHelpers.SplitPath(change.RelativePath.Value).ToList();

            // Check each relative path from root path to full path.
            var pathToItem = new RelativePath();

            foreach (var item in names)
            {
                var relativePathToItem = pathToItem.CreateChild(item);

                bool exclude;
                // For the last component, we don't know if it is a file or directory.
                // Check depending on the change kind.
                if (item == names.Last())
                {
                    // Try to avoid Disk I/O if the path should be excluded
                    var fileShouldBeIgnored      = !project.FileFilter.Include(relativePathToItem);
                    var directoryShouldBeIgnored = !project.DirectoryFilter.Include(relativePathToItem);
                    if (fileShouldBeIgnored && directoryShouldBeIgnored)
                    {
                        exclude = true;
                    }
                    else
                    {
                        if (change.ChangeKind == PathChangeKind.Deleted)
                        {
                            // Note: Not sure why this is the case.
                            exclude = false;
                        }
                        else
                        {
                            var info = _fileSystem.GetFileInfoSnapshot(change.Path);
                            if (info.IsFile)
                            {
                                exclude = fileShouldBeIgnored;
                            }
                            else if (info.IsDirectory)
                            {
                                exclude = directoryShouldBeIgnored;
                            }
                            else
                            {
                                // We don't know... Be conservative.
                                exclude = false;
                            }
                        }
                    }
                }
                else
                {
                    exclude = !project.DirectoryFilter.Include(relativePathToItem);
                }

                if (exclude)
                {
                    return(true);
                }

                pathToItem = relativePathToItem;
            }
            return(false);
        }
    private bool PathIsExcluded(PathChangeEntry change) {
      var path = change.Path;
      var project = _projectDiscovery.GetProject(path);
      if (project == null)
        return true;

      // If path is root itself, it is never excluded.
      if (path == project.RootPath)
        return false;

      // Split relative part into list of name components.
      var split = PathHelpers.SplitPrefix(path.Value, project.RootPath.Value);
      var relativePath = split.Suffix;
      var names = relativePath.Split(Path.DirectorySeparatorChar);

      // Check each relative path from root path to full path.
      var pathToItem = new RelativePath();
      foreach (var item in names) {
        var relativePathToItem = pathToItem.CreateChild(item);

        bool exclude;
        // For the last component, we might not if it is a file or directory.
        // Check depending on the change kind.
        if (item == names.Last()) {
          if (change.Kind == PathChangeKind.Deleted) {
            exclude = false;
          } else {
            var info = _fileSystem.GetFileInfoSnapshot(path);
            if (info.IsFile) {
              exclude = !project.FileFilter.Include(relativePathToItem);
            } else if (info.IsDirectory) {
              exclude = !project.DirectoryFilter.Include(relativePathToItem);
            } else {
              // We don't know... Be conservative.
              exclude = false;
            }
          }
        } else {
          exclude = !project.DirectoryFilter.Include(relativePathToItem);
        }

        if (exclude)
          return true;

        pathToItem = relativePathToItem;
      }
      return false;
    }