Skip to content

Commit fae31ee

Browse files
authored
[flutter_tools] temporary directory (#105815)
1 parent b1b1ee9 commit fae31ee

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/flutter_tools/lib/src/base/file_system.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:file/file.dart';
66
import 'package:file/local.dart' as local_fs;
77
import 'package:meta/meta.dart';
88

9+
import 'common.dart';
910
import 'io.dart';
1011
import 'platform.dart';
1112
import 'process.dart';
@@ -218,7 +219,12 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
218219
@override
219220
Directory get systemTempDirectory {
220221
if (_systemTemp == null) {
221-
_systemTemp = super.systemTempDirectory.createTempSync('flutter_tools.')
222+
if (!superSystemTempDirectory.existsSync()) {
223+
throwToolExit('Your system temp directory (${superSystemTempDirectory.path}) does not exist. '
224+
'Did you set an invalid override in your environment? See issue https://github.com/flutter/flutter/issues/74042 for more context.'
225+
);
226+
}
227+
_systemTemp = superSystemTempDirectory.createTempSync('flutter_tools.')
222228
..createSync(recursive: true);
223229
// Make sure that the temporary directory is cleaned up if the tool is
224230
// killed by a signal.
@@ -239,4 +245,8 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
239245
}
240246
return _systemTemp!;
241247
}
248+
249+
// This only exist because the memory file system does not support a systemTemp that does not exists #74042
250+
@visibleForTesting
251+
Directory get superSystemTempDirectory => super.systemTempDirectory;
242252
}

packages/flutter_tools/test/general.shard/base/file_system_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:io' as io;
77

88
import 'package:file/memory.dart';
99
import 'package:file_testing/file_testing.dart';
10+
import 'package:flutter_tools/src/base/common.dart';
1011
import 'package:flutter_tools/src/base/file_system.dart';
1112
import 'package:flutter_tools/src/base/io.dart';
1213
import 'package:flutter_tools/src/base/platform.dart';
@@ -15,6 +16,13 @@ import 'package:test/fake.dart';
1516

1617
import '../../src/common.dart';
1718

19+
class LocalFileSystemFake extends LocalFileSystem {
20+
LocalFileSystemFake.test({required super.signals}) : super.test();
21+
22+
@override
23+
Directory get superSystemTempDirectory => directory('/does_not_exist');
24+
}
25+
1826
void main() {
1927
group('fsUtils', () {
2028
late MemoryFileSystem fs;
@@ -174,6 +182,23 @@ void main() {
174182

175183
expect(temp.existsSync(), isFalse);
176184
});
185+
186+
testWithoutContext('throwToolExit when temp not found', () async {
187+
final Signals signals = Signals.test();
188+
final LocalFileSystemFake localFileSystem = LocalFileSystemFake.test(
189+
signals: signals,
190+
);
191+
192+
try {
193+
localFileSystem.systemTempDirectory;
194+
fail('expected tool exit');
195+
} on ToolExit catch(e) {
196+
expect(e.message, 'Your system temp directory (/does_not_exist) does not exist. '
197+
'Did you set an invalid override in your environment? '
198+
'See issue https://github.com/flutter/flutter/issues/74042 for more context.'
199+
);
200+
}
201+
});
177202
});
178203
}
179204

0 commit comments

Comments
 (0)