cleanup method
Clean up old files and directories
Implementation
Future<void> cleanup({Duration? olderThan}) async {
final maxAge = olderThan ?? const Duration(days: 7);
final cutoffTime = DateTime.now().subtract(maxAge);
try {
final tempDir = await getTemporaryDirectory();
final walletTempDir =
Directory(path.join(tempDir.path, _defaultDirectoryName));
if (walletTempDir.existsSync()) {
await for (final entity in walletTempDir.list()) {
final stat = await entity.stat();
if (stat.modified.isBefore(cutoffTime)) {
await entity.delete(recursive: true);
}
}
}
} catch (e) {
// Ignore cleanup errors
}
}