Chromium Code Reviews| 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"); |
| - }); |
| + } |
| } |
| } |