Repository navigation
Description
Running flutter test on macOS when the project or build/ directory resides on an external or secondary volume (/Volumes/...) can crash with an unhandled FileSystemException (OS Error: Cross-device link, errno = 18 / EXDEV) during stale native asset cleanup in _copyNativeCodeAssetsForOS (FileSystemException at _Directory._deleteSync at dart:io/directory_impl.dart-f3332222).
In packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart, _copyNativeCodeAssetsForOS deletes stale files in build/native_assets/<os>/ via:
ErrorHandlingFileSystem.deleteIfExists(entity, recursive: true);even when entity is a File (such as native_assets.json). In dart:io, File.deleteSync(recursive: true) delegates to Directory.deleteSync(recursive: true), which on macOS uses fts_open and fails with EXDEV (errno = 18) across mount/device boundaries, whereas File.deleteSync(recursive: false) calls unlink() directly. ErrorHandlingFileSystem.deleteIfExists only ignores ENOENT, so EXDEV escapes and crashes flutter_tools.
Error and stack trace:
FileSystemException: Deletion failed, path = '/Volumes/Data/.../build/native_assets/macos/native_assets.json' (OS Error: Cross-device link, errno = 18)
#0 _Directory._deleteSync (dart:io/directory_impl.dart:216:7)
#1 FileSystemEntity.deleteSync (dart:io/file_system_entity.dart:425:7)
#2 _File._deleteSync (dart:io/file_impl.dart:361:12)
#3 FileSystemEntity.deleteSync (dart:io/file_system_entity.dart:425:7)
#4 ForwardingFileSystemEntity.deleteSync (package:file/src/forwarding/forwarding_file_system_entity.dart:70:14)
#5 ErrorHandlingFile.deleteSync.<anonymous closure> (package:flutter_tools/src/base/error_handling_io.dart:458:16)
#6 _runSync (package:flutter_tools/src/base/error_handling_io.dart:1118:14)
#7 ErrorHandlingFile.deleteSync (package:flutter_tools/src/base/error_handling_io.dart:457:5)
#8 ErrorHandlingFileSystem.deleteIfExists (package:flutter_tools/src/base/error_handling_io.dart:132:14)
#9 _copyNativeCodeAssetsForOS (package:flutter_tools/src/isolated/native_assets/native_assets.dart:835:31)
#11 installCodeAssets (package:flutter_tools/src/isolated/native_assets/native_assets.dart:499:3)
#13 testCompilerBuildNativeAssets (package:flutter_tools/src/isolated/native_assets/test/native_assets.dart:122:5)
#15 TestCommand.runCommand (package:flutter_tools/src/commands/test.dart:504:41)
Related Issues & PRs
- [flutter_tools] PathNotFoundException during native assets cleanup #190234
- [flutter_tools] Fix PathNotFoundException during native assets cleanup #190102
- [stable] [flutter_tools] Fix PathNotFoundException during native assets cleanup #191279
- [tool_crash] PathNotFoundException deleting temporary directory in buildXcodeProject on macOS #195906
- [flutter_tools] Do not crash if buildXcodeProject temporary directory is deleted before cleanup #195918
Activity
[flutter_tools] Use flutterBin and package:package_config in manifest…
[flutter_tools] Simplify native_assets.json overwrite and EXDEV tests
[flutter_tools] Materialize directory listing before deleting stale n…
[flutter_tools] Avoid unlinking native_assets.json and handle EXDEV (f…