flutter_cache_manager icon indicating copy to clipboard operation
flutter_cache_manager copied to clipboard

FileSystemException: Cannot delete file

Open renefloor opened this issue 4 years ago • 13 comments

🐛 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 avatar Jun 04 '20 07:06 renefloor

@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

tamoyal avatar Apr 23 '21 01:04 tamoyal

I also upgraded and get this issue 3.0.1 as well

tamoyal avatar Apr 25 '21 01:04 tamoyal

@tamoyal can you create a reproducable example?

renefloor avatar Apr 30 '21 10:04 renefloor

I also upgraded and get this issue 3.3.0 as well

BytesZero avatar Mar 10 '22 03:03 BytesZero

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

BytesZero avatar Mar 10 '22 03:03 BytesZero

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)

danielgomezrico avatar Jul 06 '22 20:07 danielgomezrico

I got this error today, although I only could save this image:

image

There isn't an error stack other than what is displayed in the image

cdmunoz avatar Dec 13 '22 22:12 cdmunoz

Hi to all

I caught the exception while debugging and got some info (I apologize for sharing the screenshots):

  • Where the exception was thrown: image

  • The parent caller: image

It seems that after checking that the file exists… it got removed before removing it? 👀

danielgomezrico avatar Jan 04 '23 21:01 danielgomezrico

@renefloor friendly reminder 👀

danielgomezrico avatar Jan 13 '23 07:01 danielgomezrico

+1! We're having a similar, if not the same issue - https://github.com/Baseflow/flutter_cache_manager/issues/410

mapsteps avatar Apr 26 '23 17:04 mapsteps

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.

okmanideep avatar May 17 '23 06:05 okmanideep

Just tested - unfortunately, it didn't fix the issue for me.

mapsteps avatar May 17 '23 09:05 mapsteps

Any chance we will get a new version that has the PR that fixes this merged in?

JoshRice1 avatar Jan 16 '24 13:01 JoshRice1