Преглед изворни кода

Gracefully handle deletion of files in app cache

Neeraj Gupta пре 3 година
родитељ
комит
6e1f5558af
1 измењених фајлова са 4 додато и 1 уклоњено
  1. 4 1
      lib/utils/delete_file_util.dart

+ 4 - 1
lib/utils/delete_file_util.dart

@@ -274,7 +274,10 @@ Future<List<String>> _tryDeleteSharedMediaFiles(List<String> localIDs) {
           "/" +
           "/" +
           id.replaceAll(kSharedMediaIdentifier, '');
           id.replaceAll(kSharedMediaIdentifier, '');
       try {
       try {
-        await io.File(localPath).delete();
+        // verify the file exists as the OS may have already deleted it from cache
+        if (io.File(localPath).existsSync()) {
+          await io.File(localPath).delete();
+        }
         actuallyDeletedIDs.add(id);
         actuallyDeletedIDs.add(id);
       } catch (e, s) {
       } catch (e, s) {
         _logger.warning("Could not delete file " + id, e, s);
         _logger.warning("Could not delete file " + id, e, s);