Unverified Commit fae31eec authored by Jesús S Guerrero's avatar Jesús S Guerrero Committed by GitHub

[flutter_tools] temporary directory (#105815)

parent b1b1ee9c
......@@ -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;
}
......@@ -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.'
);
}
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment