Unverified Commit 302e992c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] throw a tool exit if pub cannot be run (#83293)

parent 5c3f5a7a
...@@ -148,7 +148,8 @@ class _DefaultPub implements Pub { ...@@ -148,7 +148,8 @@ class _DefaultPub implements Pub {
_processUtils = ProcessUtils( _processUtils = ProcessUtils(
logger: logger, logger: logger,
processManager: processManager, processManager: processManager,
); ),
_processManager = processManager;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Logger _logger; final Logger _logger;
...@@ -156,6 +157,7 @@ class _DefaultPub implements Pub { ...@@ -156,6 +157,7 @@ class _DefaultPub implements Pub {
final Platform _platform; final Platform _platform;
final BotDetector _botDetector; final BotDetector _botDetector;
final Usage _usage; final Usage _usage;
final ProcessManager _processManager;
@override @override
Future<void> get({ Future<void> get({
...@@ -391,11 +393,15 @@ class _DefaultPub implements Pub { ...@@ -391,11 +393,15 @@ class _DefaultPub implements Pub {
'cache', 'cache',
'dart-sdk', 'dart-sdk',
'bin', 'bin',
if (_platform.isWindows) 'pub',
'pub.bat'
else
'pub'
]); ]);
if (!_processManager.canRun(sdkPath)) {
throwToolExit(
'Your Flutter SDK download may be corrupt or missing permissions to run. '
'Try re-downloading the Flutter SDK into a directory that has read/write '
'permissions for the current user.'
);
}
return <String>[sdkPath, ...arguments]; return <String>[sdkPath, ...arguments];
} }
......
...@@ -22,6 +22,31 @@ void main() { ...@@ -22,6 +22,31 @@ void main() {
Cache.flutterRoot = ''; Cache.flutterRoot = '';
}); });
testWithoutContext('Throws a tool exit if pub cannot be run', () async {
final FakeProcessManager processManager = FakeProcessManager.empty();
final BufferLogger logger = BufferLogger.test();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
processManager.excludedExecutables.add('bin/cache/dart-sdk/bin/pub');
fileSystem.file('pubspec.yaml').createSync();
final Pub pub = Pub(
fileSystem: fileSystem,
logger: logger,
processManager: processManager,
usage: TestUsage(),
platform: FakePlatform(
environment: const <String, String>{},
),
botDetector: const BotDetectorAlwaysNo(),
);
await expectLater(() => pub.get(
context: PubContext.pubGet,
checkUpToDate: true,
), throwsToolExit(message: 'Your Flutter SDK download may be corrupt or missing permissions to run'));
});
testWithoutContext('checkUpToDate skips pub get if the package config is newer than the pubspec ' testWithoutContext('checkUpToDate skips pub get if the package config is newer than the pubspec '
'and the current framework version is the same as the last version', () async { 'and the current framework version is the same as the last version', () async {
final FakeProcessManager processManager = FakeProcessManager.empty(); final FakeProcessManager processManager = FakeProcessManager.empty();
......
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