Skip to content

Commit a2da736

Browse files
ensure Store return null if file is not cached
1 parent 5fc7752 commit a2da736

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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"}

flutter_cache_manager/example/lib/generated_plugin_registrant.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// ignore_for_file: directives_ordering
66
// ignore_for_file: lines_longer_than_80_chars
7+
// ignore_for_file: depend_on_referenced_packages
78

89
import 'package:url_launcher_web/url_launcher_web.dart';
910

flutter_cache_manager/example/linux/flutter/generated_plugins.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
66
url_launcher_linux
77
)
88

9+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
10+
)
11+
912
set(PLUGIN_BUNDLED_LIBRARIES)
1013

1114
foreach(plugin ${FLUTTER_PLUGIN_LIST})
@@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
1417
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
1518
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
1619
endforeach(plugin)
20+
21+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
23+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24+
endforeach(ffi_plugin)

flutter_cache_manager/example/windows/flutter/generated_plugins.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
66
url_launcher_windows
77
)
88

9+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
10+
)
11+
912
set(PLUGIN_BUNDLED_LIBRARIES)
1013

1114
foreach(plugin ${FLUTTER_PLUGIN_LIST})
@@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
1417
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
1518
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
1619
endforeach(plugin)
20+
21+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
22+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
23+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
24+
endforeach(ffi_plugin)

flutter_cache_manager/lib/src/cache_store.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dart:async';
2-
2+
import 'dart:io' as io;
33
import 'package:flutter_cache_manager/src/storage/file_system/file_system.dart';
44

55
import '../flutter_cache_manager.dart';
@@ -180,8 +180,9 @@ class CacheStore {
180180
if (_futureCache.containsKey(cacheObject.key)) {
181181
_futureCache.remove(cacheObject.key);
182182
}
183-
final file = await fileSystem.createFile(cacheObject.relativePath);
184-
if (await file.exists()) {
183+
final file = io.File(cacheObject.relativePath);
184+
185+
if (file.existsSync()) {
185186
await file.delete();
186187
}
187188
}

flutter_cache_manager/test/cache_store_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ import 'helpers/mock_cache_info_repository.dart';
1111
import 'helpers/test_configuration.dart';
1212

1313
void main() {
14+
late int fileId;
15+
late String fileName;
16+
late String fileUrl;
17+
late DateTime validTill;
18+
19+
late CacheObject cacheObject;
20+
21+
setUp(() {
22+
fileId = 666;
23+
fileName = 'testimage.png';
24+
fileUrl = 'baseflow.com/test.png';
25+
validTill = DateTime(2017, 9, 7, 17, 30);
26+
27+
cacheObject = CacheObject(
28+
fileUrl,
29+
relativePath: fileName,
30+
id: fileId,
31+
validTill: validTill,
32+
);
33+
});
34+
1435
group('Retrieving files from store', () {
1536
test('Store should return null when file not cached', () async {
1637
var repo = MockCacheInfoRepository();
@@ -36,6 +57,28 @@ void main() {
3657
expect(await store.getFile('baseflow.com/test.png'), isNotNull);
3758
});
3859

60+
test('Store should return null if file is not cached', () async {
61+
var config = createTestConfig();
62+
await config.returnsFile(fileName);
63+
config.returnsCacheObject(fileUrl, fileName, validTill,
64+
id: fileId, key: fileUrl);
65+
66+
var tempDir = createDir();
67+
await (await tempDir).childFile('testimage.png').create();
68+
69+
final store = CacheStore(config);
70+
71+
final _results = Future.wait([
72+
store.removeCachedFile(cacheObject),
73+
store.removeCachedFile(cacheObject),
74+
]);
75+
76+
expect(
77+
() => _results,
78+
returnsNormally,
79+
);
80+
});
81+
3982
test('Store should return null when file is no longer cached', () async {
4083
var repo = MockCacheInfoRepository();
4184

0 commit comments

Comments
 (0)