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.
This commit is contained in:
@@ -77,15 +77,23 @@ void fail(String message) {
|
||||
throw new BuildFailedError(message);
|
||||
}
|
||||
|
||||
void rm(FileSystemEntity entity) {
|
||||
if (entity.existsSync())
|
||||
entity.deleteSync();
|
||||
// Remove the given file or directory.
|
||||
void rm(FileSystemEntity entity, { bool recursive = false}) {
|
||||
if (entity.existsSync()) {
|
||||
// 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 {
|
||||
entity.deleteSync(recursive: recursive);
|
||||
} on FileSystemException catch (error) {
|
||||
print('Failed to delete ${entity.path}: $error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove recursively.
|
||||
void rmTree(FileSystemEntity entity) {
|
||||
if (entity.existsSync())
|
||||
entity.deleteSync(recursive: true);
|
||||
rm(entity, recursive: true);
|
||||
}
|
||||
|
||||
List<FileSystemEntity> ls(Directory directory) => directory.listSync();
|
||||
@@ -414,7 +422,7 @@ Future<Null> getFlutter(String revision) async {
|
||||
section('Get Flutter!');
|
||||
|
||||
if (exists(flutterDirectory)) {
|
||||
rmTree(flutterDirectory);
|
||||
flutterDirectory.deleteSync(recursive: true);
|
||||
}
|
||||
|
||||
await inDirectory(flutterDirectory.parent, () async {
|
||||
|
||||
@@ -73,8 +73,7 @@ TaskFunction createBasicMaterialCompileTest() {
|
||||
const String sampleAppName = 'sample_flutter_app';
|
||||
final Directory sampleDir = dir('${Directory.systemTemp.path}/$sampleAppName');
|
||||
|
||||
if (await sampleDir.exists())
|
||||
rmTree(sampleDir);
|
||||
rmTree(sampleDir);
|
||||
|
||||
await inDirectory(Directory.systemTemp, () async {
|
||||
await flutter('create', options: <String>[sampleAppName]);
|
||||
|
||||
@@ -33,23 +33,24 @@ class PluginTest {
|
||||
|
||||
Future<TaskResult> call() async {
|
||||
section('Create Flutter project');
|
||||
final Directory tmp = await Directory.systemTemp.createTemp('plugin');
|
||||
final FlutterProject project = await FlutterProject.create(tmp, options);
|
||||
if (buildTarget == 'ios') {
|
||||
await prepareProvisioningCertificates(project.rootPath);
|
||||
}
|
||||
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_devicelab_plugin_test.');
|
||||
try {
|
||||
section('Add plugin');
|
||||
await project.addPlugin('path_provider');
|
||||
|
||||
section('Build');
|
||||
await project.build(buildTarget);
|
||||
|
||||
final FlutterProject project = await FlutterProject.create(tempDir, options);
|
||||
try {
|
||||
if (buildTarget == 'ios')
|
||||
await prepareProvisioningCertificates(project.rootPath);
|
||||
section('Add plugin');
|
||||
await project.addPlugin('path_provider');
|
||||
section('Build');
|
||||
await project.build(buildTarget);
|
||||
} finally {
|
||||
await project.delete();
|
||||
}
|
||||
return new TaskResult.success(null);
|
||||
} catch (e) {
|
||||
return new TaskResult.failure(e.toString());
|
||||
} finally {
|
||||
await project.delete();
|
||||
rmTree(tempDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,9 +98,9 @@ class FlutterProject {
|
||||
<String>['--stop'],
|
||||
canFail: true,
|
||||
);
|
||||
// TODO(mravn): Investigating if flakiness is timing dependent.
|
||||
// TODO(ianh): Investigating if flakiness is timing dependent.
|
||||
await new Future<Null>.delayed(const Duration(seconds: 10));
|
||||
}
|
||||
await parent.delete(recursive: true);
|
||||
rmTree(parent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user