clear method
Purges all contents inside directory, preserving the directory itself.
Implementation
Future<void> clear() async {
if (!directory.existsSync()) return;
try {
await for (final entity in directory.list(followLinks: false)) {
try {
await entity.delete(recursive: true);
logger?.fine('Cleared entity: ${entity.path}');
} catch (e) {
logger?.warning(
'Failed to delete entity during clear: ${entity.path}', e);
}
}
logger?.info('Cleared directory: ${directory.path}');
} catch (e) {
logger?.warning(
'Failed to list directory during clear: ${directory.path}', e);
}
}