[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user