removeExpireLogFiles method
移除过期日志
Implementation
Future<void> removeExpireLogFiles() async {
try {
String logRootPath = await UtilFile.getFileStorageDirectory(type: FileStorageDirectoryType.log);
Directory logDirectory = Directory(logRootPath);
if (!logDirectory.existsSync()) return;
List<FileSystemEntity> dateDirectories = logDirectory.listSync();
for (FileSystemEntity entity in dateDirectories) {
if (entity is Directory) {
String dirName = p.basename(entity.path);
try {
DateTime? dirDate = DateTime.tryParse(dirName);
if (dirDate == null) continue;
final now = DateTime.now();
final difference = now.difference(dirDate).inDays;
if (difference >= ConfigStore.to.config.log.expiredDay) {
await entity.delete(recursive: true);
reportInfo('移除过期日志文件', '${entity.path} 已过期 ${difference - ConfigStore.to.config.log.expiredDay} 天');
continue;
}
} catch (e, s) {
reportError('移除过期日志文件', e, s);
continue;
}
}
}
} catch (e, s) {
reportError('移除过期日志文件', e, s);
}
}