Skip to content

Commit e8ecaf8

Browse files
committed
[flutter_tools] Simplify native_assets.json overwrite and EXDEV tests
Simplifies the fix and tests for avoiding redundant `native_assets.json` deletion and handling `EXDEV`: - Restores `ErrorHandlingFileSystem.deleteIfExists` to upstream and removes custom `ForwardingFileSystem` test doubles in `error_handling_io_test.dart`, testing `EXDEV` (`errno = 18`) directly with `MemoryFileSystem.test(opHandle: exceptionHandler.opHandle)`. - Streams `targetDir.list(followLinks: false)` in `_copyNativeCodeAssetsForOS` with `entity is File` instead of `.toList()` and `typeSync`, and deduplicates `installCodeAssets` test setup in `native_assets_test.dart`. - Removes the redundant `flutter test` subprocess integration test (`native_assets_flutter_test_manifest_overwrite_test.dart`). Reproduction notes: Both output pairs below were captured on a Linux host, which cannot reproduce the macOS external-volume behavior directly. The first pair comes from a small Dart script (`repro_exdev.dart`) calling `ErrorHandlingFileSystem.file(...).renameSync(...)` from `/tmp` (`tmpfs`) to an `ext4` directory to trigger a real kernel `EXDEV` (`errno = 18`). The second pair comes from running `BOT=true flutter test --no-pub -r expanded` on a minimal app after making `build/native_assets/linux` read-only (`chmod 0555`) while leaving `native_assets.json` writable (`0644`), so `unlink(2)` fails while in-place truncation succeeds; with a writable `build/native_assets/linux` directory, the unfixed tool passes with the same 3-line test output. Local workspace paths inside the fenced output blocks are preserved verbatim to match exact command output. Previous output: ``` Unhandled exception: FileSystemException: Cannot rename file to '/usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc4d2ca98a9/scratch/repro_196121_dst.tmp', path = '/tmp/repro_196121_src.tmp' (OS Error: Invalid cross-device link, errno = 18) #0 _File.throwIfError (dart:io/file_impl.dart:779:7) #1 _File.renameSync (dart:io/file_impl.dart:396:5) #2 ForwardingFileSystemEntity.renameSync (package:file/src/forwarding/forwarding_file_system_entity.dart:50:49) #3 ErrorHandlingFile.renameSync.<anonymous closure> (package:flutter_tools/src/base/error_handling_io.dart:430:31) #4 _runSync (package:flutter_tools/src/base/error_handling_io.dart:1116:16) #5 ErrorHandlingFile.renameSync (package:flutter_tools/src/base/error_handling_io.dart:429:12) #6 main (file:///usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc4d2ca98a9/scratch/repro_exdev.dart:24:37) flutter#7 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:313:19) flutter#8 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12) ``` Current output: ``` Flutter failed to rename file at "/tmp/repro_196121_src.tmp" to "/usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc4d2ca98a9/scratch/repro_196121_dst.tmp". A file system operation failed across different volumes or mount points. FileSystemException: Cannot rename file to '/usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc4d2ca98a9/scratch/repro_196121_dst.tmp', path = '/tmp/repro_196121_src.tmp' (OS Error: Invalid cross-device link, errno = 18) Ensure that the project, build output, and temporary directories are on the same writable volume, or check external volume and security software settings. ``` Previous output (flutter test overwriting existing native_assets.json): ``` Flutter failed to delete file at "/usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc4 d2ca98a9/scratch/repro_app/build/native_assets/linux/native_assets.json". Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user. Try running: sudo chown -R $(whoami) /usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc 4d2ca98a9/scratch/repro_app/build/native_assets/linux/native_assets.json ``` Current output (flutter test overwriting existing native_assets.json): ``` 00:00 +0: loading /usr/local/google/home/bkonyi/.gemini/jetski/brain/0a669702-1e2d-46a6-9c37-fdc4d2ca98a9/scratch/repro_app/test/smoke_test.dart 00:00 +0: smoke test 00:00 +1: All tests passed! ``` Fixes flutter#196121
1 parent bc4c193 commit e8ecaf8

6 files changed

Lines changed: 123 additions & 563 deletions

File tree

‎dev/bots/tool_test_durations.json‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
"test/integration.shard/isolated/native_assets_flutter_build_test.dart": 165,
160160
"test/integration.shard/isolated/native_assets_flutter_run_test.dart": 69,
161161
"test/integration.shard/isolated/native_assets_flutter_test_integration_test_test.dart": 33,
162-
"test/integration.shard/isolated/native_assets_flutter_test_manifest_overwrite_test.dart": 20,
163162
"test/integration.shard/isolated/native_assets_flutter_test_test.dart": 7,
164163
"test/integration.shard/isolated/native_assets_without_cbuild_assemble_test.dart": 101,
165164
"test/integration.shard/isolated/record_use_caching_test.dart": 101,
@@ -377,7 +376,6 @@
377376
"test/integration.shard/isolated/native_assets_flutter_build_test.dart": 305,
378377
"test/integration.shard/isolated/native_assets_flutter_run_test.dart": 140,
379378
"test/integration.shard/isolated/native_assets_flutter_test_integration_test_test.dart": 42,
380-
"test/integration.shard/isolated/native_assets_flutter_test_manifest_overwrite_test.dart": 20,
381379
"test/integration.shard/isolated/native_assets_flutter_test_test.dart": 12,
382380
"test/integration.shard/isolated/native_assets_without_cbuild_assemble_test.dart": 148,
383381
"test/integration.shard/isolated/record_use_caching_test.dart": 219,
@@ -595,7 +593,6 @@
595593
"test/integration.shard/isolated/native_assets_flutter_build_test.dart": 386,
596594
"test/integration.shard/isolated/native_assets_flutter_run_test.dart": 185,
597595
"test/integration.shard/isolated/native_assets_flutter_test_integration_test_test.dart": 81,
598-
"test/integration.shard/isolated/native_assets_flutter_test_manifest_overwrite_test.dart": 0,
599596
"test/integration.shard/isolated/native_assets_flutter_test_test.dart": 29,
600597
"test/integration.shard/isolated/native_assets_without_cbuild_assemble_test.dart": 97,
601598
"test/integration.shard/isolated/record_use_caching_test.dart": 310,

‎packages/flutter_tools/lib/src/base/error_handling_io.dart‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,13 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
123123
}
124124

125125
final FileSystemEntity actualEntity = switch (type) {
126-
.file ||
127-
.unixDomainSock ||
128-
.pipe => entity is File ? entity : entity.fileSystem.file(entity.path),
126+
.file => entity is File ? entity : entity.fileSystem.file(entity.path),
129127
.directory => entity is Directory ? entity : entity.fileSystem.directory(entity.path),
130128
.link => entity is Link ? entity : entity.fileSystem.link(entity.path),
131129
_ => entity,
132130
};
133131
try {
134-
actualEntity.deleteSync(recursive: type == .directory && recursive);
132+
actualEntity.deleteSync(recursive: recursive);
135133
} on FileSystemException catch (err) {
136134
// Certain error codes indicate the file could not be found. It could have
137135
// been deleted by a different program while the tool was running.

‎packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,8 @@ Future<List<File>> _copyNativeCodeAssetsForOS(
831831
targetDir.createSync(recursive: true);
832832
}
833833
final String nativeAssetsFilePath = fileSystem.file(nativeAssetsFileUri).path;
834-
for (final FileSystemEntity entity in await targetDir.list().toList()) {
835-
if (fileSystem.path.equals(entity.path, nativeAssetsFilePath) &&
836-
fileSystem.typeSync(entity.path, followLinks: false) == .file) {
834+
await for (final FileSystemEntity entity in targetDir.list(followLinks: false)) {
835+
if (entity is File && fileSystem.path.equals(entity.path, nativeAssetsFilePath)) {
837836
// _writeNativeAssetsJson immediately truncates and overwrites this
838837
// manifest file in place, so avoid unlinking it unnecessarily.
839838
continue;

0 commit comments

Comments
 (0)