File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,16 @@ class CacheManager {
7373 }
7474 }
7575
76+ Future <void > deleteFiles (List <String > resources) async {
77+ for (final resource in resources) {
78+ final filePath = get (resource);
79+ if (filePath == null ) continue ;
80+ final file = File (filePath);
81+ if (await file.exists ()) await file.delete ();
82+ print ('Deleted resource $resource stored at ${file .path }' );
83+ }
84+ }
85+
7686 Future <void > purgeOutdatedCache (int atLeastDaysOld) async {
7787 var currentResources = < String > [];
7888 for (var r in _resourcesMap.values) {
Original file line number Diff line number Diff line change @@ -129,8 +129,11 @@ class ResourceManager {
129129
130130 final checksumFailed = await validateResourcesChecksum (resources);
131131 if (checksumFailed.isNotEmpty) {
132- final mismatchedPaths = checksumFailed.map ((e) => '\n ${e .path }' ).join ();
133- throw 'Checksum validation failed for: $mismatchedPaths ' ;
132+ final checksumFailedPathString =
133+ checksumFailed.map ((e) => '\n ${e .path }' ).join ();
134+ final checksumFailedPaths = checksumFailed.map ((e) => e.path).toList ();
135+ await cacheManager.deleteFiles (checksumFailedPaths);
136+ throw 'Checksum validation failed for: $checksumFailedPathString . \n Please download the missing files again.' ;
134137 }
135138
136139 // delete downloaded archives to free up disk space
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ void main() async {
5959 expect (manager.getArchive (txtRemotePath), isNull);
6060 });
6161
62+ test ('deleteFiles' , () async {
63+ await manager.deleteFiles (paths);
64+ final txtLocalPath = manager.get (txtRemotePath);
65+ expect (txtLocalPath, isNotNull);
66+ expect (await File (txtLocalPath! ).exists (), isFalse,
67+ reason: 'file should not exist at path [$txtLocalPath ]' );
68+ });
69+
6270 test ('deleteLoadedResources' , () async {
6371 await manager.deleteLoadedResources (paths);
6472
You can’t perform that action at this time.
0 commit comments