Skip to content

Commit f6d7110

Browse files
committed
try catch on cache deletion
1 parent ccc5f8f commit f6d7110

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

flutter_cache_manager/lib/src/cache_store.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,27 @@ class CacheStore {
181181
_futureCache.remove(cacheObject.key);
182182
}
183183
final file = await fileSystem.createFile(cacheObject.relativePath);
184-
if (await file.exists()) {
185-
await file.delete();
184+
185+
bool fileExists = false;
186+
187+
try {
188+
fileExists = await file.exists();
189+
} catch (e) {
190+
cacheLogger.log(
191+
'CacheManager: Failed to check if file exists: $e',
192+
CacheManagerLogLevel.warning,
193+
);
194+
}
195+
196+
if (fileExists) {
197+
try {
198+
await file.delete();
199+
} catch (e) {
200+
cacheLogger.log(
201+
'CacheManager: Failed to delete file: $e',
202+
CacheManagerLogLevel.warning,
203+
);
204+
}
186205
}
187206
}
188207

0 commit comments

Comments
 (0)