From 25c2c22d2921c9e5407542960a043c8bca423b20 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Fri, 10 Feb 2023 18:39:58 +0100 Subject: [PATCH] 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 --------- Co-authored-by: Christopher Fujino --- packages/flutter_tools/lib/src/web/chrome.dart | 6 ++++++ .../test/web.shard/chrome_test.dart | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/web/chrome.dart b/packages/flutter_tools/lib/src/web/chrome.dart index e91cb8f80c..b7abbab4a1 100644 --- a/packages/flutter_tools/lib/src/web/chrome.dart +++ b/packages/flutter_tools/lib/src/web/chrome.dart @@ -222,6 +222,12 @@ class ChromiumLauncher { if (process != null && cacheDir != null) { unawaited(process.exitCode.whenComplete(() { _cacheUserSessionInformation(userDataDir, cacheDir); + // cleanup temp dir + try { + userDataDir.deleteSync(recursive: true); + } on FileSystemException { + // ignore + } })); } return connect(Chromium( diff --git a/packages/flutter_tools/test/web.shard/chrome_test.dart b/packages/flutter_tools/test/web.shard/chrome_test.dart index 1e4e54bb27..dacc69eced 100644 --- a/packages/flutter_tools/test/web.shard/chrome_test.dart +++ b/packages/flutter_tools/test/web.shard/chrome_test.dart @@ -419,13 +419,6 @@ void main() { cacheDir: dataDir, ); - exitCompleter.complete(); - await Future.delayed(const Duration(milliseconds: 1)); - - // writes non-crash back to dart_tool - expect(preferencesFile.readAsStringSync(), '"exit_type":"Normal"'); - - // validate any Default content is copied final Directory defaultContentDir = fileSystem .directory('.tmp_rand0/flutter_tools_chrome_device.rand0') @@ -434,6 +427,12 @@ void main() { expect(defaultContentDir, exists); + exitCompleter.complete(); + await Future.delayed(const Duration(milliseconds: 1)); + + // writes non-crash back to dart_tool + expect(preferencesFile.readAsStringSync(), '"exit_type":"Normal"'); + // Validate cache dirs are not copied. for (final String cache in kCodeCache) { expect(fileSystem @@ -441,6 +440,9 @@ void main() { .childDirectory('Default') .childDirectory(cache), isNot(exists)); } + + // validate defaultContentDir is deleted after exit, data is in cache + expect(defaultContentDir, isNot(exists)); }); testWithoutContext('can retry launch when glibc bug happens', () async {