Skip to content

Commit 9c588f3

Browse files
authored
Fix flutter tool crash on upgrade caused by app-jit (#111879)
Fix flutter tool crash on upgrade caused by app-jit
1 parent 4bc714f commit 9c588f3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

bin/internal/shared.bat

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SETLOCAL
1616
SET flutter_tools_dir=%FLUTTER_ROOT%\packages\flutter_tools
1717
SET cache_dir=%FLUTTER_ROOT%\bin\cache
1818
SET snapshot_path=%cache_dir%\flutter_tools.snapshot
19+
SET snapshot_path_old=%cache_dir%\flutter_tools.snapshot.old
1920
SET stamp_path=%cache_dir%\flutter_tools.stamp
2021
SET script_path=%flutter_tools_dir%\bin\flutter_tools.dart
2122
SET dart_sdk_path=%cache_dir%\dart-sdk
@@ -170,6 +171,21 @@ GOTO :after_subroutine
170171

171172
POPD
172173

174+
REM Move the old snapshot - we can't just overwrite it as the VM might currently have it
175+
REM memory mapped (e.g. on flutter upgrade), and deleting it might not work if the file
176+
REM is in use. For downloading a new dart sdk the folder is moved, so we take the same
177+
REM approach of moving the file here.
178+
SET /A snapshot_path_suffix=1
179+
:move_old_snapshot
180+
IF EXIST "%snapshot_path_old%%snapshot_path_suffix%" (
181+
SET /A snapshot_path_suffix+=1
182+
GOTO move_old_snapshot
183+
) ELSE (
184+
IF EXIST "%snapshot_path%" (
185+
MOVE "%snapshot_path%" "%snapshot_path_old%%snapshot_path_suffix%" 2> NUL > NUL
186+
)
187+
)
188+
173189
IF "%FLUTTER_TOOL_ARGS%" == "" (
174190
"%dart%" --verbosity=error --snapshot="%snapshot_path%" --snapshot-kind="app-jit" --packages="%flutter_tools_dir%\.dart_tool\package_config.json" --no-enable-mirrors "%script_path%" > NUL
175191
) else (
@@ -182,6 +198,9 @@ GOTO :after_subroutine
182198
)
183199
>"%stamp_path%" ECHO %compilekey%
184200

201+
REM Try to delete any old snapshots now. Swallow any errors though.
202+
DEL "%snapshot_path%.old*" 2> NUL > NUL
203+
185204
REM Exit Subroutine
186205
EXIT /B
187206

bin/internal/shared.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,22 @@ function upgrade_flutter () (
154154
fi
155155
pub_upgrade_with_retry
156156

157+
# Move the old snapshot - we can't just overwrite it as the VM might currently have it
158+
# memory mapped (e.g. on flutter upgrade). For downloading a new dart sdk the folder is moved,
159+
# so we take the same approach of moving the file here.
160+
SNAPSHOT_PATH_OLD="$SNAPSHOT_PATH.old"
161+
if [ -f "$SNAPSHOT_PATH" ]; then
162+
mv "$SNAPSHOT_PATH" "$SNAPSHOT_PATH_OLD"
163+
fi
164+
157165
# Compile...
158166
"$DART" --verbosity=error --disable-dart-dev $FLUTTER_TOOL_ARGS --snapshot="$SNAPSHOT_PATH" --snapshot-kind="app-jit" --packages="$FLUTTER_TOOLS_DIR/.dart_tool/package_config.json" --no-enable-mirrors "$SCRIPT_PATH" > /dev/null
159167
echo "$compilekey" > "$STAMP_PATH"
168+
169+
# Delete any temporary snapshot path.
170+
if [ -f "$SNAPSHOT_PATH_OLD" ]; then
171+
rm -f "$SNAPSHOT_PATH_OLD"
172+
fi
160173
fi
161174
# The exit here is extraneous since the function is run in a subshell, but
162175
# this serves as documentation that running the function in a subshell is

0 commit comments

Comments
 (0)