mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] use ProcessManager.canRun instead of checking for ArgumentErrors (#83845)
This commit is contained in:
parent
320f27713b
commit
53e0c50a7c
@ -222,13 +222,7 @@ class _PosixUtils extends OperatingSystemUtils {
|
||||
// unzip -o -q zipfile -d dest
|
||||
@override
|
||||
void unzip(File file, Directory targetDirectory) {
|
||||
try {
|
||||
_processUtils.runSync(
|
||||
<String>['unzip', '-o', '-q', file.path, '-d', targetDirectory.path],
|
||||
throwOnError: true,
|
||||
verboseExceptions: true,
|
||||
);
|
||||
} on ArgumentError {
|
||||
if (!_processManager.canRun('unzip')) {
|
||||
// unzip is not available. this error message is modeled after the download
|
||||
// error in bin/internal/update_dart_sdk.sh
|
||||
String message = 'Please install unzip.';
|
||||
@ -241,6 +235,11 @@ class _PosixUtils extends OperatingSystemUtils {
|
||||
'Missing "unzip" tool. Unable to extract ${file.path}.\n$message'
|
||||
);
|
||||
}
|
||||
_processUtils.runSync(
|
||||
<String>['unzip', '-o', '-q', file.path, '-d', targetDirectory.path],
|
||||
throwOnError: true,
|
||||
verboseExceptions: true,
|
||||
);
|
||||
}
|
||||
|
||||
// tar -xzf tarball -C dest
|
||||
@ -454,11 +453,7 @@ class _WindowsUtils extends OperatingSystemUtils {
|
||||
|
||||
@override
|
||||
List<File> _which(String execName, { bool all = false }) {
|
||||
// `where` always returns all matches, not just the first one.
|
||||
ProcessResult result;
|
||||
try {
|
||||
result = _processManager.runSync(<String>['where', execName]);
|
||||
} on ArgumentError {
|
||||
if (!_processManager.canRun('where')) {
|
||||
// `where` could be missing if system32 is not on the PATH.
|
||||
throwToolExit(
|
||||
'Cannot find the executable for `where`. This can happen if the System32 '
|
||||
@ -467,6 +462,8 @@ class _WindowsUtils extends OperatingSystemUtils {
|
||||
'the terminal and/or IDE.'
|
||||
);
|
||||
}
|
||||
// `where` always returns all matches, not just the first one.
|
||||
final ProcessResult result = _processManager.runSync(<String>['where', execName]);
|
||||
if (result.exitCode != 0) {
|
||||
return const <File>[];
|
||||
}
|
||||
|
@ -81,16 +81,8 @@ void main() {
|
||||
});
|
||||
|
||||
group('which on Windows', () {
|
||||
testWithoutContext('throws tool exit if where throws an argument error', () async {
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'where',
|
||||
kExecutable,
|
||||
],
|
||||
exception: ArgumentError('Cannot find executable for where'),
|
||||
),
|
||||
);
|
||||
testWithoutContext('throws tool exit if where.exe cannot be run', () async {
|
||||
fakeProcessManager.excludedExecutables.add('where');
|
||||
|
||||
final OperatingSystemUtils utils = OperatingSystemUtils(
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
@ -544,17 +536,10 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
group('display an install message when unzip throws an ArgumentError', () {
|
||||
group('display an install message when unzip cannot be run', () {
|
||||
testWithoutContext('Linux', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
|
||||
],
|
||||
exception: ArgumentError(),
|
||||
),
|
||||
);
|
||||
fakeProcessManager.excludedExecutables.add('unzip');
|
||||
|
||||
final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
@ -573,14 +558,7 @@ void main() {
|
||||
|
||||
testWithoutContext('macOS', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
|
||||
],
|
||||
exception: ArgumentError(),
|
||||
),
|
||||
);
|
||||
fakeProcessManager.excludedExecutables.add('unzip');
|
||||
|
||||
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
@ -590,7 +568,7 @@ void main() {
|
||||
);
|
||||
|
||||
expect(
|
||||
() => macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
|
||||
() => macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
|
||||
throwsToolExit
|
||||
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
|
||||
'Consider running "brew install unzip".'),
|
||||
@ -599,14 +577,7 @@ void main() {
|
||||
|
||||
testWithoutContext('unknown OS', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
fakeProcessManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[
|
||||
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
|
||||
],
|
||||
exception: ArgumentError(),
|
||||
),
|
||||
);
|
||||
fakeProcessManager.excludedExecutables.add('unzip');
|
||||
|
||||
final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
|
Loading…
Reference in New Issue
Block a user