writeStallDumpToDisk function
The disk sink: one directory per dump, payload.bin (raw,
byte-identical) + meta.json (the pure side's redacted/serialized
meta). Returns the meta.json path, or null on any failure
(best-effort — the abort path outranks the capture).
Implementation
Future<String?> writeStallDumpToDisk(StallDump dump) async {
final root = stallDumpDirectory();
final stamp = dump.dumpedAt.toIso8601String().replaceAll(RegExp('[:.]'), '-');
final dir = Directory(
'${root.path}${Platform.pathSeparator}stall-$stamp-${dump.watchdog}',
);
dir.createSync(recursive: true);
final bytes = dump.payloadBytes;
if (bytes != null) {
File(
'${dir.path}${Platform.pathSeparator}payload.bin',
).writeAsBytesSync(bytes, flush: true);
}
final metaFile = File('${dir.path}${Platform.pathSeparator}meta.json');
metaFile.writeAsStringSync(serializeStallMeta(dump), flush: true);
return metaFile.path;
}