Repository navigation
Commit fdbb6f0
authored
[flutter_tools] Avoid unlinking native_assets.json and handle EXDEV (flutter#196134)
Previously, `installCodeAssets` invoked `_copyNativeCodeAssetsForOS` on
every `flutter test` run, which listed `build/native_assets/<os>/` and
deleted `native_assets.json` right before `_writeNativeAssetsJson`
truncated and overwrote that same file in place. On macOS external
volumes (for example `/Volumes/...` where endpoint-security or
recycle-bin interposers intercept `unlink(2)` and attempt a cross-volume
`rename(2)`), unlinking `native_assets.json` failed with
`FileSystemException (OS Error: Cross-device link, errno = 18)`
(`EXDEV`). In addition, `_handlePosixException` did not map `EXDEV`
(`errno = 18`) to a `ToolExit`.
This change:
1. Skips deleting `native_assets.json` in `_copyNativeCodeAssetsForOS`
when it already exists on disk as a regular file, since
`_writeNativeAssetsJson` immediately truncates and overwrites it in
place (while still deleting stale bundled native asset artifacts,
directories, and symlinks).
2. Handles POSIX `EXDEV` (`errno = 18`) in `_handlePosixException` on
Linux and macOS by throwing an actionable `ToolExit` instead of crashing
with an unhandled `FileSystemException`.
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)
#7 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:313:19)
#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#1961211 parent e63a332 commit fdbb6f0
4 files changed
Lines changed: 247 additions & 1 deletion
File tree
- packages/flutter_tools
- lib/src
- base
- isolated/native_assets
- test/general.shard
- base
- isolated
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1383 | 1383 | | |
1384 | 1384 | | |
1385 | 1385 | | |
| 1386 | + | |
1386 | 1387 | | |
1387 | 1388 | | |
1388 | 1389 | | |
| |||
1392 | 1393 | | |
1393 | 1394 | | |
1394 | 1395 | | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
1395 | 1402 | | |
1396 | 1403 | | |
1397 | 1404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
| 530 | + | |
530 | 531 | | |
531 | 532 | | |
532 | 533 | | |
| |||
812 | 813 | | |
813 | 814 | | |
814 | 815 | | |
| 816 | + | |
815 | 817 | | |
816 | 818 | | |
817 | 819 | | |
| |||
828 | 830 | | |
829 | 831 | | |
830 | 832 | | |
831 | | - | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
832 | 840 | | |
833 | 841 | | |
834 | 842 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
484 | 485 | | |
485 | 486 | | |
486 | 487 | | |
| |||
765 | 766 | | |
766 | 767 | | |
767 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
768 | 825 | | |
769 | 826 | | |
770 | 827 | | |
771 | 828 | | |
772 | 829 | | |
773 | 830 | | |
| 831 | + | |
774 | 832 | | |
775 | 833 | | |
776 | 834 | | |
| |||
1053 | 1111 | | |
1054 | 1112 | | |
1055 | 1113 | | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1056 | 1162 | | |
1057 | 1163 | | |
1058 | 1164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
535 | 536 | | |
536 | 537 | | |
537 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
538 | 663 | | |
539 | 664 | | |
540 | 665 | | |
| |||
0 commit comments