Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: tools/testing/dart/test_progress.dart

Issue 2848103002: Move test.dart into testing/dart. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/testing/dart/main.dart ('K') | « tools/testing/dart/main.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/test_progress.dart
diff --git a/tools/testing/dart/test_progress.dart b/tools/testing/dart/test_progress.dart
index cadbceb4ff6ebfca5e35a69617a5c030a9767514..804aa7860ad85cc3997c111f00525687d6d1439d 100644
--- a/tools/testing/dart/test_progress.dart
+++ b/tools/testing/dart/test_progress.dart
@@ -4,7 +4,6 @@
library test_progress;
-import "dart:async";
import "dart:io";
import "dart:io" as io;
import "dart:convert" show JSON;
@@ -502,10 +501,14 @@ class SkippedCompilationsPrinter extends EventListener {
}
}
+/// Discovers directories in the system temp directory that appear to have been
+/// created by "dart:io"'s `Directory.createTemp()` method.
class LeftOverTempDirPrinter extends EventListener {
- final MIN_NUMBER_OF_TEMP_DIRS = 50;
+ /// The minimum number of left over temp directories that is considered
+ /// excessive and causes a warning to be shown.
+ static const _excessiveCount = 50;
- static RegExp _getTemporaryDirectoryRegexp() {
+ static RegExp get _tempDirPattern {
// These are the patterns of temporary directory names created by
// 'Directory.systemTemp.createTemp()' on linux/macos and windows.
if (['macos', 'linux'].contains(Platform.operatingSystem)) {
@@ -515,29 +518,41 @@ class LeftOverTempDirPrinter extends EventListener {
}
}
- static Stream<FileSystemEntity> getLeftOverTemporaryDirectories() {
- var regExp = _getTemporaryDirectoryRegexp();
- return Directory.systemTemp.list().where((FileSystemEntity fse) {
- if (fse is Directory) {
- if (regExp.hasMatch(new Path(fse.path).filename)) {
- return true;
- }
+ /// Returns a stream of all of the apparently Dart-created temp directories.
+ static Iterable<Directory> list() {
+ return Directory.systemTemp
+ .listSync()
+ .where((FileSystemEntity entity) =>
+ entity is Directory &&
+ _tempDirPattern.hasMatch(new Path(entity.path).filename))
+ .map((entity) => entity as Directory);
+ }
+
+ /// Attempts to delete all Dart-created temp directories.
+ ///
+ /// If any deletion fails, logs it and continues to delete others.
+ static void deleteAll() {
+ for (var directory in LeftOverTempDirPrinter.list()) {
+ try {
+ directory.deleteSync(recursive: true);
+ } catch (error) {
+ DebugLogger.error(error);
}
- return false;
- });
+ }
}
void allDone() {
Bill Hesse 2017/05/02 14:33:09 Could you try to locally test this code, by adding
Bob Nystrom 2017/05/02 23:48:15 Uh, now that you mention it, no, it does not seem
- getLeftOverTemporaryDirectories().length.then((int count) {
- if (count > MIN_NUMBER_OF_TEMP_DIRS) {
- DebugLogger.warning("There are ${count} directories "
- "in the system tempdir "
- "('${Directory.systemTemp.path}')! "
- "Maybe left over directories?\n");
+ try {
+ var count = list().length;
+ if (count > _excessiveCount) {
+ DebugLogger
+ .warning("There are $count directories in the system tempdir "
+ "('${Directory.systemTemp.path}'). "
+ "Maybe left over directories?\n");
}
- }).catchError((error) {
+ } catch (error) {
DebugLogger.warning("Could not list temp directories, got: $error");
- });
+ }
}
}
« tools/testing/dart/main.dart ('K') | « tools/testing/dart/main.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698