flutter_cache_manager
flutter_cache_manager copied to clipboard
FileSystemException: Cannot delete file
🐛 Bug Report
App throws exception FileSystemException: Cannot delete file
Expected behavior
Should not delete file when it doesn't exist
Reproduction steps
Bug found in: https://github.com/Baseflow/flutter_cached_network_image/issues/335#issuecomment-629190486
Configuration
Version: 1.3.0
Platform:
- [X] :iphone: iOS
- [X] :robot: Android
@renefloor I actually still get this error. I'm on version 2.1.2
but I see this fix was submitted way before that release. I don't do any explicit deleting on my end so I think it has to be a library bug? My stacktrace is:
FileSystemException: FileSystemException: Cannot delete file, path = '/var/mobile/Containers/Data/Application/6867986F-318E-4E1D-AF0D-EA736FDD62C7/Library/Caches/audioCache/fc00b6f0-a082-11eb-8599-91285352f656.file' (OS Error: No such file or directory, errno = 2)
File "file_impl.dart", line 283, in _File._delete.<fn>
File "zone.dart", line 1362, in _rootRunUnary
File "zone.dart", line 1265, in _CustomZone.runUnary
File "future_impl.dart", line 152, in _FutureListener.handleValue
File "future_impl.dart", line 704, in Future._propagateToListeners.handleValueCallback
File "future_impl.dart", line 733, in Future._propagateToListeners
File "future_impl.dart", line 539, in Future._completeWithValue
File "future_impl.dart", line 577, in Future._asyncCompleteWithValue.<fn>
File "zone.dart", line 1354, in _rootRun
File "zone.dart", line 1258, in _CustomZone.run
File "zone.dart", line 1162, in _CustomZone.runGuarded
File "zone.dart", line 1202, in _CustomZone.bindCallbackGuarded.<fn>
File "schedule_microtask.dart", line 40, in _microtaskLoop
File "schedule_microtask.dart", line 49, in _startMicrotaskLoop
I also upgraded and get this issue 3.0.1
as well
@tamoyal can you create a reproducable example?
I also upgraded and get this issue 3.3.0
as well
https://github.com/Baseflow/flutter_cached_network_image/issues/335 @renefloor Is a similar problem recurring?
#4 CacheStore._removeCachedFile (package:flutter_cache_manager/src/cache_store.dart:190)
https://github.com/Baseflow/flutter_cache_manager/blob/205387b4c7e4faff5152848b68c98d36e989ec01/flutter_cache_manager/lib/src/cache_store.dart#L183-L186
L185 => L190
I see that there is already a judgment on whether the file exists, I don't know why this error still occurs
Im facing this with:
- Cached network image 3.2.1 (which is the last one at the moment) and it internally uses
flutter_cache_manager 3.3.0
)
I got this error today, although I only could save this image:
There isn't an error stack other than what is displayed in the image
Hi to all
I caught the exception while debugging and got some info (I apologize for sharing the screenshots):
-
Where the exception was thrown:
-
The parent caller:
It seems that after checking that the file exists… it got removed before removing it? 👀
@renefloor friendly reminder 👀
+1! We're having a similar, if not the same issue - https://github.com/Baseflow/flutter_cache_manager/issues/410
How about
if (await file.exists()) {
+ try {
await file.delete();
+ } on PathNotFoundException catch (e) {
+ // File has already been deleted. Do nothing #184
+ }
}
?
Since the file.exists()
check is asynchronous. Can't actually rely on it fully. If the above logic is triggered back to back with the same file, the second delete is expected to cause this exception.
Just tested - unfortunately, it didn't fix the issue for me.
Any chance we will get a new version that has the PR that fixes this merged in?