Skip to content

[stable] [flutter_tools] Fix PathNotFoundException during native assets cleanup - #191279

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.47-candidate.0from
flutteractionsbot:cp-stable-7e85c6b68a66ab880add22a38689d4cc03d28b16
Aug 18, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:flutter-3.47-candidate.0from
flutteractionsbot:cp-stable-7e85c6b68a66ab880add22a38689d4cc03d28b16

Conversation

@flutteractionsbot

@flutteractionsbot flutteractionsbot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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_tools iterated over files and called delete on 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 unhandled PathNotFoundException. 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 clean or rebuild the application.

Risk:

  • Low
  • Medium
  • High

Test Coverage:

  • Yes
  • No

Validation Steps:

  1. Build a project using native assets across multiple targets or runs.
  2. Verify that cleaning native asset build directories handles missing or transient files gracefully via deleteIfExists without throwing PathNotFoundException.
  3. Run packages/flutter_tools unit tests.

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
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Aug 18, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor Author

@bkonyi please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 18, 2026
@flutter-dashboard

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
for (final FileSystemEntity entity in await targetDir.list().toList()) {
for (final FileSystemEntity entity in await targetDir.list(followLinks: false).toList()) {
References
  1. Check for potential regressions: Look for changes that might break existing functionality or introduce unexpected behavior in related areas. (link)

@bkonyi bkonyi changed the title [CP-stable][flutter_tools] Fix PathNotFoundException during native assets cleanup [stable] [flutter_tools] Fix PathNotFoundException during native assets cleanup Aug 18, 2026
@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 18, 2026
@auto-submit
auto-submit Bot merged commit 3faa26f into flutter:flutter-3.47-candidate.0 Aug 18, 2026
10 checks passed
@flutteractionsbot
flutteractionsbot deleted the cp-stable-7e85c6b68a66ab880add22a38689d4cc03d28b16 branch August 18, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants