From 472c8e1cf04997029b904022c5fa0e56adc71087 Mon Sep 17 00:00:00 2001 From: Mateus Siqueira <54752439+mateussiqueira@users.noreply.github.com> Date: Tue, 26 Jul 2022 10:06:04 -0300 Subject: [PATCH 1/5] ensure Store return null if file is not cached --- .../.flutter-plugins-dependencies | 1 + .../lib/generated_plugin_registrant.dart | 17 ++++++++ .../lib/src/cache_store.dart | 6 ++- .../test/cache_store_test.dart | 43 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 flutter_cache_manager/.flutter-plugins-dependencies create mode 100644 flutter_cache_manager/example/lib/generated_plugin_registrant.dart diff --git a/flutter_cache_manager/.flutter-plugins-dependencies b/flutter_cache_manager/.flutter-plugins-dependencies new file mode 100644 index 00000000..78f9fd4c --- /dev/null +++ b/flutter_cache_manager/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.10/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.16/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.6/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.7/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.1.0/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-07-26 10:05:46.413539","version":"3.0.4"} \ No newline at end of file diff --git a/flutter_cache_manager/example/lib/generated_plugin_registrant.dart b/flutter_cache_manager/example/lib/generated_plugin_registrant.dart new file mode 100644 index 00000000..40a0d005 --- /dev/null +++ b/flutter_cache_manager/example/lib/generated_plugin_registrant.dart @@ -0,0 +1,17 @@ +// +// Generated file. Do not edit. +// + +// ignore_for_file: directives_ordering +// ignore_for_file: lines_longer_than_80_chars +// ignore_for_file: depend_on_referenced_packages + +import 'package:url_launcher_web/url_launcher_web.dart'; + +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; + +// ignore: public_member_api_docs +void registerPlugins(Registrar registrar) { + UrlLauncherPlugin.registerWith(registrar); + registrar.registerMessageHandler(); +} diff --git a/flutter_cache_manager/lib/src/cache_store.dart b/flutter_cache_manager/lib/src/cache_store.dart index c213b144..dca3a648 100644 --- a/flutter_cache_manager/lib/src/cache_store.dart +++ b/flutter_cache_manager/lib/src/cache_store.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; +import 'dart:io' as io; import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart'; ///Flutter Cache Manager @@ -181,8 +182,9 @@ class CacheStore { if (_futureCache.containsKey(cacheObject.key)) { _futureCache.remove(cacheObject.key); } - final file = await fileSystem.createFile(cacheObject.relativePath); - if (await file.exists()) { + final file = io.File(cacheObject.relativePath); + + if (file.existsSync()) { await file.delete(); } } diff --git a/flutter_cache_manager/test/cache_store_test.dart b/flutter_cache_manager/test/cache_store_test.dart index b440164c..6767d453 100644 --- a/flutter_cache_manager/test/cache_store_test.dart +++ b/flutter_cache_manager/test/cache_store_test.dart @@ -11,6 +11,27 @@ import 'helpers/mock_cache_info_repository.dart'; import 'helpers/test_configuration.dart'; void main() { + late int fileId; + late String fileName; + late String fileUrl; + late DateTime validTill; + + late CacheObject cacheObject; + + setUp(() { + fileId = 666; + fileName = 'testimage.png'; + fileUrl = 'baseflow.com/test.png'; + validTill = DateTime(2017, 9, 7, 17, 30); + + cacheObject = CacheObject( + fileUrl, + relativePath: fileName, + id: fileId, + validTill: validTill, + ); + }); + group('Retrieving files from store', () { test('Store should return null when file not cached', () async { var repo = MockCacheInfoRepository(); @@ -36,6 +57,28 @@ void main() { expect(await store.getFile('baseflow.com/test.png'), isNotNull); }); + test('Store should return null if file is not cached', () async { + var config = createTestConfig(); + await config.returnsFile(fileName); + config.returnsCacheObject(fileUrl, fileName, validTill, + id: fileId, key: fileUrl); + + var tempDir = createDir(); + await (await tempDir).childFile('testimage.png').create(); + + final store = CacheStore(config); + + final _results = Future.wait([ + store.removeCachedFile(cacheObject), + store.removeCachedFile(cacheObject), + ]); + + expect( + () => _results, + returnsNormally, + ); + }); + test('Store should return null when file is no longer cached', () async { var repo = MockCacheInfoRepository(); From 1f72221093a8addd49a6f115646fc330e2546dc1 Mon Sep 17 00:00:00 2001 From: Mateus Siqueira <54752439+mateussiqueira@users.noreply.github.com> Date: Tue, 26 Jul 2022 10:06:34 -0300 Subject: [PATCH 2/5] move const values to the setup --- flutter_cache_manager/.flutter-plugins-dependencies | 2 +- flutter_cache_manager/test/cache_store_test.dart | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/flutter_cache_manager/.flutter-plugins-dependencies b/flutter_cache_manager/.flutter-plugins-dependencies index 78f9fd4c..903a165c 100644 --- a/flutter_cache_manager/.flutter-plugins-dependencies +++ b/flutter_cache_manager/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.10/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.16/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.6/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.7/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.1.0/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-07-26 10:05:46.413539","version":"3.0.4"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.10/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.16/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.6/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.7/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.1.0/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-07-26 10:06:23.183472","version":"3.0.4"} \ No newline at end of file diff --git a/flutter_cache_manager/test/cache_store_test.dart b/flutter_cache_manager/test/cache_store_test.dart index 6767d453..bdb35c75 100644 --- a/flutter_cache_manager/test/cache_store_test.dart +++ b/flutter_cache_manager/test/cache_store_test.dart @@ -42,9 +42,6 @@ void main() { }); test('Store should return FileInfo when file is cached', () async { - var fileName = 'testimage.png'; - var fileUrl = 'baseflow.com/test.png'; - var config = createTestConfig(); await config.returnsFile(fileName); config.returnsCacheObject(fileUrl, fileName, DateTime.now()); @@ -102,9 +99,6 @@ void main() { }); test('Store should return CacheInfo when file is cached', () async { - var fileName = 'testimage.png'; - var fileUrl = 'baseflow.com/test.png'; - var config = createTestConfig(); await config.returnsFile(fileName); config.returnsCacheObject(fileUrl, fileName, DateTime.now(), id: 1); @@ -117,8 +111,6 @@ void main() { test('Store should return CacheInfo from memory when asked twice', () async { - var fileName = 'testimage.png'; - var fileUrl = 'baseflow.com/test.png'; var validTill = DateTime.now(); var config = createTestConfig(); @@ -139,8 +131,6 @@ void main() { test( 'Store should return File from memcache only when file is retrieved before', () async { - var fileName = 'testimage.png'; - var fileUrl = 'baseflow.com/test.png'; var validTill = DateTime.now(); var config = createTestConfig(); @@ -215,8 +205,6 @@ void main() { group('Removing files in store', () { test('Store should remove fileinfo from repo on delete', () async { - var fileName = 'testimage.png'; - var fileUrl = 'baseflow.com/test.png'; var validTill = DateTime.now(); var config = createTestConfig(); From d569cead12988737bf18217ede9db5401ffd1c03 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 31 Jul 2024 21:32:17 +0200 Subject: [PATCH 3/5] Delete flutter_cache_manager/.flutter-plugins-dependencies --- flutter_cache_manager/.flutter-plugins-dependencies | 1 - 1 file changed, 1 deletion(-) delete mode 100644 flutter_cache_manager/.flutter-plugins-dependencies diff --git a/flutter_cache_manager/.flutter-plugins-dependencies b/flutter_cache_manager/.flutter-plugins-dependencies deleted file mode 100644 index 903a165c..00000000 --- a/flutter_cache_manager/.flutter-plugins-dependencies +++ /dev/null @@ -1 +0,0 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.10/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.16/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.6/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.3/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.7/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/mateussiqueira/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.1.0/","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2022-07-26 10:06:23.183472","version":"3.0.4"} \ No newline at end of file From 801b713ed638d2cc0062686624c294712e6328bb Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 31 Jul 2024 21:45:11 +0200 Subject: [PATCH 4/5] Delete flutter_cache_manager/example/lib/generated_plugin_registrant.dart --- .../lib/generated_plugin_registrant.dart | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 flutter_cache_manager/example/lib/generated_plugin_registrant.dart diff --git a/flutter_cache_manager/example/lib/generated_plugin_registrant.dart b/flutter_cache_manager/example/lib/generated_plugin_registrant.dart deleted file mode 100644 index 40a0d005..00000000 --- a/flutter_cache_manager/example/lib/generated_plugin_registrant.dart +++ /dev/null @@ -1,17 +0,0 @@ -// -// Generated file. Do not edit. -// - -// ignore_for_file: directives_ordering -// ignore_for_file: lines_longer_than_80_chars -// ignore_for_file: depend_on_referenced_packages - -import 'package:url_launcher_web/url_launcher_web.dart'; - -import 'package:flutter_web_plugins/flutter_web_plugins.dart'; - -// ignore: public_member_api_docs -void registerPlugins(Registrar registrar) { - UrlLauncherPlugin.registerWith(registrar); - registrar.registerMessageHandler(); -} From 35085bf182e570c3e0a546c45bf0c2e947542499 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 31 Jul 2024 21:49:49 +0200 Subject: [PATCH 5/5] Format --- .gitignore | 91 ++++++++++++++----- .../test/cache_store_test.dart | 4 +- 2 files changed, 70 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 856e7441..b22a5648 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,11 @@ .atom/ .buildlog/ .history -.project .svn/ -bin/ +devtools_options.yaml + +# Environment files +ios/Flutter/Dart-Defines.xcconfig # IntelliJ related *.iml @@ -18,30 +20,23 @@ bin/ *.iws .idea/ -# Android Studio related -android/.classpath -android/.settings/ - # Visual Studio Code related -.vscode/ - -# Flutter repo-specific -/bin/cache/ -/bin/mingit/ -/dev/benchmarks/mega_gallery/ -/dev/bots/.recipe_deps -/dev/bots/android_tools/ -/dev/docs/doc/ -/dev/docs/lib/ -/dev/docs/pubspec.yaml -/packages/flutter/coverage/ -version +.classpath +.project +.settings/ +.vscode/* + +# packages file containing multi-root paths +.packages.generated # Flutter/Dart/Pub related **/doc/api/ .dart_tool/ .flutter-plugins +.flutter-plugins-dependencies +**/generated_plugin_registrant.dart .packages +.pub-preload-cache/ .pub-cache/ .pub/ build/ @@ -49,16 +44,17 @@ flutter_*.png linked_*.ds unlinked.ds unlinked_spec.ds -flutter_export_environment.sh # Android related **/android/**/gradle-wrapper.jar -**/android/.gradle +.gradle/ **/android/captures/ **/android/gradlew **/android/gradlew.bat **/android/local.properties **/android/**/GeneratedPluginRegistrant.java +**/android/key.properties +*.jks # iOS/XCode related **/ios/**/*.mode1v3 @@ -77,20 +73,69 @@ flutter_export_environment.sh **/ios/**/profile **/ios/**/xcuserdata **/ios/.generated/ +**/ios/Flutter/.last_build_id **/ios/Flutter/App.framework **/ios/Flutter/Flutter.framework +**/ios/Flutter/Flutter.podspec **/ios/Flutter/Generated.xcconfig +**/ios/Flutter/ephemeral **/ios/Flutter/app.flx **/ios/Flutter/app.zip **/ios/Flutter/flutter_assets/ +**/ios/Flutter/flutter_export_environment.sh **/ios/ServiceDefinitions.json **/ios/Runner/GeneratedPluginRegistrant.* +# macOS +**/Flutter/ephemeral/ +**/Pods/ +**/macos/Flutter/GeneratedPluginRegistrant.swift +**/macos/Flutter/ephemeral +**/xcuserdata/ + +# Windows +**/windows/flutter/generated_plugin_registrant.cc +**/windows/flutter/generated_plugin_registrant.h +**/windows/flutter/generated_plugins.cmake + +# Linux +**/linux/flutter/generated_plugin_registrant.cc +**/linux/flutter/generated_plugin_registrant.h +**/linux/flutter/generated_plugins.cmake + +# Coverage +coverage/ + +# Submodules +packages/**/pubspec.lock + +# Web related +lib/generated_plugin_registrant.dart + +# Symbols +app.*.symbols + +# Obfuscation related +app.*.map.json + # Exceptions to above rules. !**/ios/**/default.mode1v3 !**/ios/**/default.mode2v3 !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages -example/.flutter-plugins-dependencies -flutter_cache_manager/example/ios/Flutter/.last_build_id +!/dev/ci/**/Gemfile.lock +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.idea/codeStyles/ +!.idea/dictionaries/ +!.idea/runConfigurations/ + +# Generated files +**/generated +*.g.dart + +# Injection generated files +injectable.config.dart \ No newline at end of file diff --git a/flutter_cache_manager/test/cache_store_test.dart b/flutter_cache_manager/test/cache_store_test.dart index bdb35c75..b9a7ccd4 100644 --- a/flutter_cache_manager/test/cache_store_test.dart +++ b/flutter_cache_manager/test/cache_store_test.dart @@ -65,13 +65,13 @@ void main() { final store = CacheStore(config); - final _results = Future.wait([ + final results = Future.wait([ store.removeCachedFile(cacheObject), store.removeCachedFile(cacheObject), ]); expect( - () => _results, + () => results, returnsNormally, ); });