[flutter_tools] handle missing zip/unzip argument errors (#66685)

it is possible for users that download the prebuilt SDKs to run the tool without unzip installed. Rather than crashing with an unclear argument error, exit the tool with a message on how to install that mirrors the message in the update_dart_sdk.sh script.

Also applied to zip for completeness
This commit is contained in:
Jonah Williams
2020-09-29 07:58:09 -07:00
committed by GitHub
parent 5872b70b8c
commit 6f20c8a83f
2 changed files with 138 additions and 10 deletions

View File

@@ -208,21 +208,50 @@ class _PosixUtils extends OperatingSystemUtils {
@override
void zip(Directory data, File zipFile) {
_processUtils.runSync(
<String>['zip', '-r', '-q', zipFile.path, '.'],
workingDirectory: data.path,
throwOnError: true,
);
try {
_processUtils.runSync(
<String>['zip', '-r', '-q', zipFile.path, '.'],
workingDirectory: data.path,
throwOnError: true,
verboseExceptions: true,
);
} on ArgumentError {
// zip is not available. this error message is modeled after the download
// error in bin/internal/update_dart_sdk.sh
String message = 'Please install zip.';
if (_platform.isMacOS) {
message = 'Consider running "brew install zip".';
} else if (_platform.isLinux) {
message = 'Consider running "sudo apt-get install zip".';
}
throwToolExit(
'Missing "zip" tool. Unable to compress ${data.path}.\n$message'
);
}
}
// unzip -o -q zipfile -d dest
@override
void unzip(File file, Directory targetDirectory) {
_processUtils.runSync(
<String>['unzip', '-o', '-q', file.path, '-d', targetDirectory.path],
throwOnError: true,
verboseExceptions: true,
);
try {
_processUtils.runSync(
<String>['unzip', '-o', '-q', file.path, '-d', targetDirectory.path],
throwOnError: true,
verboseExceptions: true,
);
} on ArgumentError {
// 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.';
if (_platform.isMacOS) {
message = 'Consider running "brew install unzip".';
} else if (_platform.isLinux) {
message = 'Consider running "sudo apt-get install unzip".';
}
throwToolExit(
'Missing "unzip" tool. Unable to extract ${file.path}.\n$message'
);
}
}
// tar -xzf tarball -C dest