Skip to content

Commit

Permalink
Avoiding deletion of .db files
Browse files Browse the repository at this point in the history
  • Loading branch information
DGoiana authored and limwa committed Mar 7, 2024
1 parent 503a391 commit 08baa2f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions uni/lib/controller/cleanup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uni/controller/local_storage/database/app_bus_stop_database.dart';
Expand Down Expand Up @@ -56,16 +57,16 @@ Future<void> cleanupCachedFiles() async {

Future<void> cleanDirectory(Directory directory, DateTime threshold) async {
final entities = directory.listSync(recursive: true, followLinks: false);
final toDeleteEntities = entities.where((e) {
final toDeleteEntities = entities.whereType<File>().where((file) {
try {
final fileDate = File(e.path).lastModifiedSync();
return fileDate.isBefore(threshold);
final fileDate = File(file.path).lastModifiedSync();
return fileDate.isBefore(threshold) && path.extension(file.path) != '.db';
} catch (e) {
return false;
}
});

for (final entity in toDeleteEntities) {
await File(entity.path).delete();
entity.deleteSync();
}
}

0 comments on commit 08baa2f

Please sign in to comment.