Skip to content

[tool_crash] FileSystemException (OS Error: Cross-device link, errno = 18) deleting stale native asset files in _copyNativeCodeAssetsForOS on macOS #196121

Closed

Description

@bkonyi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listc: crashStack traces logged to the consolefound in release: 3.47Found to occur in 3.47platform-macosBuilding on or for macOS specificallyt: top-crasherteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions