list method
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 prefix = normalizeRepoPath(path);
final base = prefix.isEmpty ? '' : '$prefix/';
final dirs = <String>{};
final entries = <RepoEntry>[];
for (final filePath in _files.keys) {
if (base.isNotEmpty && !filePath.startsWith(base)) continue;
final rest = filePath.substring(base.length);
if (rest.isEmpty) continue;
final segs = rest.split('/');
final depth = segs.length; // 1 == direct child
if (!recursive && depth > 1) {
// Only surface the immediate directory.
final dir = '$base${segs.first}';
if (dirs.add(dir)) {
entries.add(RepoEntry(path: dir, name: segs.first, isDir: true));
}
continue;
}
if (maxDepth != null && depth > maxDepth) continue;
if (!matchesGlob(filePath, glob)) continue;
entries.add(
RepoEntry(
path: filePath,
name: segs.last,
isDir: false,
size: _files[filePath]!.length,
),
);
}
entries.sort((a, b) => a.path.compareTo(b.path));
return entries;
}