delete static method
Delete this project's state. Idempotent.
The legacy pointer goes too, but only while it still describes THIS project. A sibling that started later owns it by then, and taking it away would break the connected commands of an app that is still running.
Implementation
static Future<void> delete() async {
final String sessionPath = path;
final Map<String, dynamic>? mine = await _readFile(sessionPath);
final file = File(sessionPath);
if (file.existsSync()) await file.delete();
if (sessionPath == legacyPointerPath) return;
final File pointer = File(legacyPointerPath);
if (!pointer.existsSync()) return;
final Map<String, dynamic>? pointed = await _readFile(legacyPointerPath);
final Object? pointedRoot = pointed?['projectRoot'];
// A pointer with no recorded root is the hand-written recovery file the
// read path goes out of its way to honour. Deleting it here took away
// the escape hatch people reach for precisely when `start` has already
// failed them, so an unattributed pointer is left alone.
if (pointedRoot is! String || pointedRoot.isEmpty) return;
// IS-WITHIN, matching sessionOwnershipError: a `stop` run from a
// subdirectory has no session file of its own, so `mine` is null and
// the fallback root is that subdirectory. Comparing exactly left the
// pointer behind, still advertising a session that had just been
// stopped.
final String myRoot = (mine?['projectRoot'] as String?) ?? _projectRoot();
if (_isWithin(myRoot, pointedRoot)) {
await pointer.delete();
}
}