Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemException: Cannot delete file #184

Closed
2 tasks done
renefloor opened this issue Jun 4, 2020 · 13 comments · Fixed by #185 or #423
Closed
2 tasks done

FileSystemException: Cannot delete file #184

renefloor opened this issue Jun 4, 2020 · 13 comments · Fixed by #185 or #423

Comments

@renefloor
Copy link
Collaborator

🐛 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: Baseflow/flutter_cached_network_image#335 (comment)

Configuration

Version: 1.3.0

Platform:

  • 📱 iOS
  • 🤖 Android
@tamoyal
Copy link

tamoyal commented Apr 23, 2021

@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
Copy link

tamoyal commented Apr 25, 2021

I also upgraded and get this issue 3.0.1 as well

@renefloor
Copy link
Collaborator Author

@tamoyal can you create a reproducable example?

@renefloor renefloor reopened this Apr 30, 2021
@BytesZero
Copy link

I also upgraded and get this issue 3.3.0 as well

@BytesZero
Copy link

Baseflow/flutter_cached_network_image#335
@renefloor Is a similar problem recurring?

#4 CacheStore._removeCachedFile (package:flutter_cache_manager/src/cache_store.dart:190)

final file = await fileSystem.createFile(cacheObject.relativePath);
if (await file.exists()) {
await file.delete();
}

L185 => L190

I see that there is already a judgment on whether the file exists, I don't know why this error still occurs

@danielgomezrico
Copy link

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)

@cdmunoz
Copy link

cdmunoz commented Dec 13, 2022

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

@danielgomezrico
Copy link

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
Copy link

@renefloor friendly reminder 👀

DucLQ92 added a commit to DucLQ92/flutter_cache_manager that referenced this issue Mar 15, 2023
@mapsteps
Copy link

+1! We're having a similar, if not the same issue - #410

@okmanideep
Copy link

okmanideep commented May 17, 2023

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.

@mapsteps
Copy link

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

@JoshRice1
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants