list method

  1. @override
Future<List<RepoEntry>> list(
  1. String path, {
  2. bool recursive = false,
  3. int? maxDepth,
  4. String? glob,
})
override

Lists the directory at path. When recursive, descends up to maxDepth levels; glob filters entries by name/path pattern.

Implementation

@override
Future<List<RepoEntry>> list(
  String path, {
  bool recursive = false,
  int? maxDepth,
  String? glob,
}) async {
  final dir = Directory(_resolve(path));
  if (!dir.existsSync()) throw RepoException('Directory not found: $path');
  final entries = <RepoEntry>[];
  final baseDepth = _resolve(path).split('/').length;
  await for (final ent in dir.list(
    recursive: recursive,
    followLinks: false,
  )) {
    final rel = _relativeOf(ent.path);
    if (_ignored(rel)) continue;
    if (maxDepth != null) {
      final depth = ent.path.split('/').length - baseDepth + 1;
      if (depth > maxDepth) continue;
    }
    final isDir = ent is Directory;
    if (!isDir && !matchesGlob(rel, glob)) continue;
    entries.add(
      RepoEntry(
        path: rel,
        name: rel.split('/').last,
        isDir: isDir,
        size: ent is File ? ent.lengthSync() : null,
      ),
    );
    if (entries.length >= config.maxResults) break;
  }
  entries.sort((a, b) => a.path.compareTo(b.path));
  return entries;
}