Skip to content

Commit

Permalink
Delete Chrome temp cache after closing (#119062)
Browse files Browse the repository at this point in the history
* Delete Chrome temp cache after closeing

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

Co-authored-by: Christopher Fujino <fujino@google.com>

---------

Co-authored-by: Christopher Fujino <fujino@google.com>
  • Loading branch information
passsy and christopherfujino authored Feb 10, 2023
1 parent 298c874 commit 25c2c22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/flutter_tools/lib/src/web/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions packages/flutter_tools/test/web.shard/chrome_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,6 @@ void main() {
cacheDir: dataDir,
);

exitCompleter.complete();
await Future<void>.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')
Expand All @@ -434,13 +427,22 @@ void main() {

expect(defaultContentDir, exists);

exitCompleter.complete();
await Future<void>.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
.directory('.tmp_rand0/flutter_tools_chrome_device.rand0')
.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 {
Expand Down

0 comments on commit 25c2c22

Please sign in to comment.