Unverified Commit ae207b5e authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Handle permission error during flutter clean (#43401)

parent eba69caf
......@@ -83,9 +83,15 @@ class CleanCommand extends FlutterCommand {
@visibleForTesting
void deleteFile(FileSystemEntity file) {
// This will throw a FileSystemException if the directory is missing permissions.
try {
if (!file.existsSync()) {
return;
}
} on FileSystemException catch (err) {
printError('Cannot clean ${file.path}.\n$err');
return;
}
final Status deletionStatus = logger.startProgress('Deleting ${file.basename}...', timeout: timeoutConfiguration.fastOperation);
try {
file.deleteSync(recursive: true);
......
......@@ -80,6 +80,24 @@ void main() {
Logger: () => BufferLogger(),
Xcode: () => mockXcode,
});
testUsingContext('$CleanCommand handles missing permissions;', () async {
when(mockXcode.isInstalledAndMeetsVersionCheck).thenReturn(false);
final MockFile mockFile = MockFile();
when(mockFile.existsSync()).thenThrow(const FileSystemException('OS error: Access Denied'));
when(mockFile.path).thenReturn('foo.dart');
final BufferLogger logger = context.get<Logger>();
final CleanCommand command = CleanCommand();
command.deleteFile(mockFile);
expect(logger.errorText, contains('Cannot clean foo.dart'));
verifyNever(mockFile.deleteSync(recursive: true));
}, overrides: <Type, Generator>{
Platform: () => windowsPlatform,
Logger: () => BufferLogger(),
Xcode: () => mockXcode,
});
}
test1();
......
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