purge method

Future<int> purge({
  1. PurgeReport? plan,
})

Delete every directory listed in PurgeReport.directoriesToDelete. Idempotent — directories that disappear between dryRun and purge are silently skipped. Returns the number of directories actually deleted.

Implementation

Future<int> purge({PurgeReport? plan}) async {
  final PurgeReport p = plan ?? dryRun();
  int deleted = 0;
  for (final String path in p.directoriesToDelete) {
    final Directory dir = Directory(path);
    if (!dir.existsSync()) {
      verbose('  Already gone: $path');
      continue;
    }
    try {
      await dir.delete(recursive: true);
      verbose('  Deleted: $path');
      deleted++;
    } catch (e) {
      warn('  Could not delete $path: $e');
    }
  }
  return deleted;
}