Iterable listSync()

in lib/src/list_tree.dart [409:464]


  Iterable<FileSystemEntity> listSync(String dir, FileSystem fileSystem,
      {bool followLinks = true}) {
    if (isRecursive) {
      return fileSystem
          .directory(dir)
          .listSync(recursive: true, followLinks: followLinks)
          .where((entity) => _matches(p.relative(entity.path, from: dir)));
    }

    // Don't spawn extra [Directory.listSync] calls when we already know exactly
    // which subdirectories we're interested in.
    if (_isIntermediate && _caseSensitive) {
      return children!.entries.expand((entry) {
        var sequence = entry.key;
        var child = entry.value;
        return child.listSync(
            p.join(dir, (sequence.nodes.single as LiteralNode).text),
            fileSystem,
            followLinks: followLinks);
      });
    }

    var entities = fileSystem.directory(dir).listSync(followLinks: followLinks);
    _validateIntermediateChildrenSync(dir, entities, fileSystem);

    return entities.expand((entity) {
      var entities = <FileSystemEntity>[];
      var basename = p.relative(entity.path, from: dir);
      if (_matches(basename)) entities.add(entity);
      if (entity is! Directory) return entities;

      entities.addAll(children!.keys
          .where((sequence) => sequence.matches(basename))
          .expand((sequence) {
        try {
          return children![sequence]!
              .listSync(p.join(dir, basename), fileSystem,
                  followLinks: followLinks)
              .toList();
        } on FileSystemException catch (error) {
          // Ignore errors from directories not existing. We do this here so
          // that we only ignore warnings below wild cards. For example, the
          // glob "foo/bar/*/baz" should fail if "foo/bar" doesn't exist but
          // succeed if "foo/bar/qux/baz" doesn't exist.
          if (error.osError!.errorCode == _enoent ||
              error.osError!.errorCode == _enoentWin) {
            return const [];
          } else {
            rethrow;
          }
        }
      }));

      return entities;
    });
  }