[flutter_tools] handle OSError 2 from current working directory (#78380)
This commit is contained in:
@@ -24,6 +24,10 @@ import 'platform.dart';
|
||||
// ToolExit and a message that is more clear than the FileSystemException by
|
||||
// itself.
|
||||
|
||||
/// On windows this is error code 2: ERROR_FILE_NOT_FOUND, and on
|
||||
/// macOS/Linux it is error code 2/ENOENT: No such file or directory.
|
||||
const int kSystemCannotFindFile = 2;
|
||||
|
||||
/// A [FileSystem] that throws a [ToolExit] on certain errors.
|
||||
///
|
||||
/// If a [FileSystem] error is not caused by the Flutter tool, and can only be
|
||||
@@ -83,10 +87,6 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
|
||||
// Certain error codes indicate the file could not be found. It could have
|
||||
// been deleted by a different program while the tool was running.
|
||||
// if it still exists, the file likely exists on a read-only volume.
|
||||
//
|
||||
// On windows this is error code 2: ERROR_FILE_NOT_FOUND, and on
|
||||
// macOS/Linux it is error code 2/ENOENT: No such file or directory.
|
||||
const int kSystemCannotFindFile = 2;
|
||||
if (err?.osError?.errorCode != kSystemCannotFindFile || _noExitOnFailure) {
|
||||
rethrow;
|
||||
}
|
||||
@@ -105,7 +105,18 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
|
||||
|
||||
@override
|
||||
Directory get currentDirectory {
|
||||
return _runSync(() => directory(delegate.currentDirectory), platform: _platform);
|
||||
try {
|
||||
return _runSync(() => directory(delegate.currentDirectory), platform: _platform);
|
||||
} on FileSystemException catch (err) {
|
||||
// Special handling for OS error 2 for current directory only.
|
||||
if (err.osError.errorCode == kSystemCannotFindFile) {
|
||||
throwToolExit(
|
||||
'Unable to read current working directory. This can happen if the directory the '
|
||||
'Flutter tool was run from was moved or deleted.'
|
||||
);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user