From fae31eecce8a488f7ad49635ebcde7a6660820a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20S=20Guerrero?= Date: Thu, 16 Jun 2022 19:58:05 -0700 Subject: [PATCH] [flutter_tools] temporary directory (#105815) --- .../lib/src/base/file_system.dart | 12 ++++++++- .../general.shard/base/file_system_test.dart | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/base/file_system.dart b/packages/flutter_tools/lib/src/base/file_system.dart index 3df9270e188f..7feb83fea14e 100644 --- a/packages/flutter_tools/lib/src/base/file_system.dart +++ b/packages/flutter_tools/lib/src/base/file_system.dart @@ -6,6 +6,7 @@ import 'package:file/file.dart'; import 'package:file/local.dart' as local_fs; import 'package:meta/meta.dart'; +import 'common.dart'; import 'io.dart'; import 'platform.dart'; import 'process.dart'; @@ -218,7 +219,12 @@ class LocalFileSystem extends local_fs.LocalFileSystem { @override Directory get systemTempDirectory { if (_systemTemp == null) { - _systemTemp = super.systemTempDirectory.createTempSync('flutter_tools.') + if (!superSystemTempDirectory.existsSync()) { + throwToolExit('Your system temp directory (${superSystemTempDirectory.path}) does not exist. ' + 'Did you set an invalid override in your environment? See issue https://github.com/flutter/flutter/issues/74042 for more context.' + ); + } + _systemTemp = superSystemTempDirectory.createTempSync('flutter_tools.') ..createSync(recursive: true); // Make sure that the temporary directory is cleaned up if the tool is // killed by a signal. @@ -239,4 +245,8 @@ class LocalFileSystem extends local_fs.LocalFileSystem { } return _systemTemp!; } + + // This only exist because the memory file system does not support a systemTemp that does not exists #74042 + @visibleForTesting + Directory get superSystemTempDirectory => super.systemTempDirectory; } diff --git a/packages/flutter_tools/test/general.shard/base/file_system_test.dart b/packages/flutter_tools/test/general.shard/base/file_system_test.dart index 4848e881da96..a3bbad5e198b 100644 --- a/packages/flutter_tools/test/general.shard/base/file_system_test.dart +++ b/packages/flutter_tools/test/general.shard/base/file_system_test.dart @@ -7,6 +7,7 @@ import 'dart:io' as io; import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; +import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/platform.dart'; @@ -15,6 +16,13 @@ import 'package:test/fake.dart'; import '../../src/common.dart'; +class LocalFileSystemFake extends LocalFileSystem { + LocalFileSystemFake.test({required super.signals}) : super.test(); + + @override + Directory get superSystemTempDirectory => directory('/does_not_exist'); +} + void main() { group('fsUtils', () { late MemoryFileSystem fs; @@ -174,6 +182,23 @@ void main() { expect(temp.existsSync(), isFalse); }); + + testWithoutContext('throwToolExit when temp not found', () async { + final Signals signals = Signals.test(); + final LocalFileSystemFake localFileSystem = LocalFileSystemFake.test( + signals: signals, + ); + + try { + localFileSystem.systemTempDirectory; + fail('expected tool exit'); + } on ToolExit catch(e) { + expect(e.message, 'Your system temp directory (/does_not_exist) does not exist. ' + 'Did you set an invalid override in your environment? ' + 'See issue https://github.com/flutter/flutter/issues/74042 for more context.' + ); + } + }); }); }