@@ -16,6 +16,7 @@ SETLOCAL
16
16
SET flutter_tools_dir = %FLUTTER_ROOT% \packages\flutter_tools
17
17
SET cache_dir = %FLUTTER_ROOT% \bin\cache
18
18
SET snapshot_path = %cache_dir% \flutter_tools.snapshot
19
+ SET snapshot_path_old = %cache_dir% \flutter_tools.snapshot.old
19
20
SET stamp_path = %cache_dir% \flutter_tools.stamp
20
21
SET script_path = %flutter_tools_dir% \bin\flutter_tools.dart
21
22
SET dart_sdk_path = %cache_dir% \dart-sdk
@@ -170,6 +171,21 @@ GOTO :after_subroutine
170
171
171
172
POPD
172
173
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
+
173
189
IF " %FLUTTER_TOOL_ARGS% " == " " (
174
190
" %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
175
191
) else (
@@ -182,6 +198,9 @@ GOTO :after_subroutine
182
198
)
183
199
> " %stamp_path% " ECHO %compilekey%
184
200
201
+ REM Try to delete any old snapshots now. Swallow any errors though.
202
+ DEL " %snapshot_path% .old*" 2 > NUL > NUL
203
+
185
204
REM Exit Subroutine
186
205
EXIT /B
187
206
0 commit comments