Skip to content

Commit

Permalink
Delete resources which failed checksum validation
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Feb 10, 2025
1 parent 399ee37 commit d962da3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions flutter/lib/resources/cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ class CacheManager {
}
}

Future<void> deleteFiles(List<String> resources) async {
for (final resource in resources) {
final filePath = get(resource);
if (filePath == null) continue;
final file = File(filePath);
if (await file.exists()) await file.delete();
print('Deleted resource $resource stored at ${file.path}');
}
}

Future<void> purgeOutdatedCache(int atLeastDaysOld) async {
var currentResources = <String>[];
for (var r in _resourcesMap.values) {
Expand Down
7 changes: 5 additions & 2 deletions flutter/lib/resources/resource_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ class ResourceManager {

final checksumFailed = await validateResourcesChecksum(resources);
if (checksumFailed.isNotEmpty) {
final mismatchedPaths = checksumFailed.map((e) => '\n${e.path}').join();
throw 'Checksum validation failed for: $mismatchedPaths';
final checksumFailedPathString =
checksumFailed.map((e) => '\n${e.path}').join();
final checksumFailedPaths = checksumFailed.map((e) => e.path).toList();
await cacheManager.deleteFiles(checksumFailedPaths);
throw 'Checksum validation failed for: $checksumFailedPathString. \nPlease download the missing files again.';
}

// delete downloaded archives to free up disk space
Expand Down

0 comments on commit d962da3

Please # to comment.