Clean up usage of temporary directories (#20682)
All temporary directory start with `flutter_` and have their random component separated from the name by a period, as in `flutter_test_bundle.YFYQMY`.
I've tried to find some of the places where we didn't cleanly delete temporary directories, too. This greatly reduces, though it does not entirely eliminate, the directories we leave behind when running tests, especially `flutter_tools` tests.
While I was at it I standardized on `tempDir` as the variable name for temporary directories, since it was the most common, removing occurrences of `temp` and `tmp`, among others.
Also I factored out some common code that used to catch exceptions that happen on Windows, and made more places use that pattern.
diff --git a/packages/flutter_driver/test/common.dart b/packages/flutter_driver/test/common.dart
index b36d043..dbc658f 100644
--- a/packages/flutter_driver/test/common.dart
+++ b/packages/flutter_driver/test/common.dart
@@ -2,13 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'dart:io';
+
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
import 'package:test/test.dart' as test_package show TypeMatcher;
export 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
// Defines a 'package:test' shim.
-// TODO(ianh): Remove this file once https://github.com/dart-lang/matcher/issues/98 is fixed
+// TODO(ianh): Clean this up once https://github.com/dart-lang/matcher/issues/98 is fixed
/// A matcher that compares the type of the actual value to the type argument T.
Matcher isInstanceOf<T>() => new test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
+
+void tryToDelete(Directory directory) {
+ // This should not be necessary, but it turns out that
+ // on Windows it's common for deletions to fail due to
+ // bogus (we think) "access denied" errors.
+ try {
+ directory.deleteSync(recursive: true);
+ } on FileSystemException catch (error) {
+ print('Failed to delete ${directory.path}: $error');
+ }
+}
\ No newline at end of file