Skip to content

Commit 25c2c22

Browse files
Delete Chrome temp cache after closing (#119062)
* Delete Chrome temp cache after closeing * Update packages/flutter_tools/lib/src/web/chrome.dart Co-authored-by: Christopher Fujino <[email protected]> --------- Co-authored-by: Christopher Fujino <[email protected]>
1 parent 298c874 commit 25c2c22

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/flutter_tools/lib/src/web/chrome.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ class ChromiumLauncher {
222222
if (process != null && cacheDir != null) {
223223
unawaited(process.exitCode.whenComplete(() {
224224
_cacheUserSessionInformation(userDataDir, cacheDir);
225+
// cleanup temp dir
226+
try {
227+
userDataDir.deleteSync(recursive: true);
228+
} on FileSystemException {
229+
// ignore
230+
}
225231
}));
226232
}
227233
return connect(Chromium(

packages/flutter_tools/test/web.shard/chrome_test.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,6 @@ void main() {
419419
cacheDir: dataDir,
420420
);
421421

422-
exitCompleter.complete();
423-
await Future<void>.delayed(const Duration(milliseconds: 1));
424-
425-
// writes non-crash back to dart_tool
426-
expect(preferencesFile.readAsStringSync(), '"exit_type":"Normal"');
427-
428-
429422
// validate any Default content is copied
430423
final Directory defaultContentDir = fileSystem
431424
.directory('.tmp_rand0/flutter_tools_chrome_device.rand0')
@@ -434,13 +427,22 @@ void main() {
434427

435428
expect(defaultContentDir, exists);
436429

430+
exitCompleter.complete();
431+
await Future<void>.delayed(const Duration(milliseconds: 1));
432+
433+
// writes non-crash back to dart_tool
434+
expect(preferencesFile.readAsStringSync(), '"exit_type":"Normal"');
435+
437436
// Validate cache dirs are not copied.
438437
for (final String cache in kCodeCache) {
439438
expect(fileSystem
440439
.directory('.tmp_rand0/flutter_tools_chrome_device.rand0')
441440
.childDirectory('Default')
442441
.childDirectory(cache), isNot(exists));
443442
}
443+
444+
// validate defaultContentDir is deleted after exit, data is in cache
445+
expect(defaultContentDir, isNot(exists));
444446
});
445447

446448
testWithoutContext('can retry launch when glibc bug happens', () async {

0 commit comments

Comments
 (0)