stat method

  1. @override
Future<RepoStat> stat(
  1. String path
)
override

Metadata for path (never throws for a missing path — returns exists: false).

Implementation

@override
Future<RepoStat> stat(String path) async {
  final full = _resolve(path);
  final type = FileSystemEntity.typeSync(full, followLinks: false);
  if (type == FileSystemEntityType.notFound) {
    return RepoStat(
      path: normalizeRepoPath(path),
      exists: false,
      isDir: false,
      size: 0,
      lineCount: 0,
    );
  }
  final isDir = type == FileSystemEntityType.directory;
  var size = 0;
  var lineCount = 0;
  String? modified;
  if (!isDir) {
    final file = File(full);
    size = file.lengthSync();
    modified = file.lastModifiedSync().toIso8601String();
    if (size <= config.maxFileBytes) {
      lineCount = splitLines(file.readAsStringSync()).length;
    }
  }
  return RepoStat(
    path: normalizeRepoPath(path),
    exists: true,
    isDir: isDir,
    size: size,
    lineCount: lineCount,
    modified: modified,
  );
}