Handle permission error during flutter clean (#43401)
This commit is contained in:
parent
eba69caf97
commit
ae207b5e42
@ -83,7 +83,13 @@ class CleanCommand extends FlutterCommand {
|
||||
|
||||
@visibleForTesting
|
||||
void deleteFile(FileSystemEntity file) {
|
||||
if (!file.existsSync()) {
|
||||
// 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);
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user