Repository navigation
[stable] [flutter_tools] Fix PathNotFoundException during native assets cleanup - #191279
Conversation
flutter#190102) Avoid crashing with a PathNotFoundException if a file is deleted by the OS or another process after being listed but before being deleted by the tool. Use ErrorHandlingFileSystem.deleteIfExists instead of entity.delete. Fixes flutter#190234
|
@bkonyi please fill out the PR description above, afterwards the release team will review this request. |
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request updates the native assets cleanup logic to use ErrorHandlingFileSystem.deleteIfExists when removing stale files in the target directory, and adds a corresponding regression test. The reviewer suggested using followLinks: false when listing directory entities to prevent recursively deleting files outside the target directory if symlinks are present.
| } | ||
| await for (final FileSystemEntity entity in targetDir.list()) { | ||
| await entity.delete(recursive: true); | ||
| for (final FileSystemEntity entity in await targetDir.list().toList()) { |
There was a problem hiding this comment.
When cleaning up a directory, it is safer to list entities with followLinks: false. If followLinks is true (the default), directory listing will resolve symlinks. If there are symlinks pointing to external directories, deleting them recursively could potentially traverse and delete files outside of the target directory, or at least cause unexpected behavior. Setting followLinks: false ensures we only delete the symlinks themselves.
| for (final FileSystemEntity entity in await targetDir.list().toList()) { | |
| for (final FileSystemEntity entity in await targetDir.list(followLinks: false).toList()) { |
References
- Check for potential regressions: Look for changes that might break existing functionality or introduce unexpected behavior in related areas. (link)
3faa26f
into
flutter:flutter-3.47-candidate.0
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
#190234
Impact Description:
During native assets cleanup in
_copyNativeCodeAssetsForOS,flutter_toolsiterated over files and calleddeleteon each entity. If a file (such as a temporary or OS metadata file) was removed concurrently between listing and deletion, the tool crashed with an unhandledPathNotFoundException. This was identified as a top-10 crash signature in Flutter stable release 3.44.8.Changelog Description:
[flutter/190234] Avoid crashing with PathNotFoundException when cleaning up native assets if files are removed concurrently.
Workaround:
Rerun
flutter cleanor rebuild the application.Risk:
Test Coverage:
Validation Steps:
deleteIfExistswithout throwingPathNotFoundException.packages/flutter_toolsunit tests.