@@ -21,9 +21,13 @@ import 'platform.dart';
21
21
// ToolExit and a message that is more clear than the FileSystemException by
22
22
// itself.
23
23
24
- /// On windows this is error code 2: ERROR_FILE_NOT_FOUND, and on
24
+ /// On Windows this is error code 2: ERROR_FILE_NOT_FOUND, and on
25
25
/// macOS/Linux it is error code 2/ENOENT: No such file or directory.
26
- const int kSystemCannotFindFile = 2 ;
26
+ const int kSystemCodeCannotFindFile = 2 ;
27
+
28
+ /// On Windows this error is 3: ERROR_PATH_NOT_FOUND, and on
29
+ /// macOS/Linux, it is error code 3/ESRCH: No such process.
30
+ const int kSystemCodePathNotFound = 3 ;
27
31
28
32
/// A [FileSystem] that throws a [ToolExit] on certain errors.
29
33
///
@@ -72,22 +76,26 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
72
76
/// This method should be preferred to checking if it exists and
73
77
/// then deleting, because it handles the edge case where the file or directory
74
78
/// is deleted by a different program between the two calls.
75
- static bool deleteIfExists (FileSystemEntity file , {bool recursive = false }) {
76
- if (! file .existsSync ()) {
79
+ static bool deleteIfExists (FileSystemEntity entity , {bool recursive = false }) {
80
+ if (! entity .existsSync ()) {
77
81
return false ;
78
82
}
79
83
try {
80
- file .deleteSync (recursive: recursive);
84
+ entity .deleteSync (recursive: recursive);
81
85
} on FileSystemException catch (err) {
82
86
// Certain error codes indicate the file could not be found. It could have
83
87
// been deleted by a different program while the tool was running.
84
88
// if it still exists, the file likely exists on a read-only volume.
85
- if (err.osError? .errorCode != kSystemCannotFindFile || _noExitOnFailure) {
89
+ // This check will falsely match "3/ESRCH: No such process" on Linux/macOS,
90
+ // but this should be fine since this code should never come up here.
91
+ final bool codeCorrespondsToPathOrFileNotFound = err.osError? .errorCode == kSystemCodeCannotFindFile ||
92
+ err.osError? .errorCode == kSystemCodePathNotFound;
93
+ if (! codeCorrespondsToPathOrFileNotFound || _noExitOnFailure) {
86
94
rethrow ;
87
95
}
88
- if (file .existsSync ()) {
96
+ if (entity .existsSync ()) {
89
97
throwToolExit (
90
- 'The Flutter tool tried to delete the file or directory ${file .path } but was '
98
+ 'The Flutter tool tried to delete the file or directory ${entity .path } but was '
91
99
"unable to. This may be due to the file and/or project's location on a read-only "
92
100
'volume. Consider relocating the project and trying again' ,
93
101
);
@@ -104,7 +112,7 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
104
112
return _runSync (() => directory (delegate.currentDirectory), platform: _platform);
105
113
} on FileSystemException catch (err) {
106
114
// Special handling for OS error 2 for current directory only.
107
- if (err.osError? .errorCode == kSystemCannotFindFile ) {
115
+ if (err.osError? .errorCode == kSystemCodeCannotFindFile ) {
108
116
throwToolExit (
109
117
'Unable to read current working directory. This can happen if the directory the '
110
118
'Flutter tool was run from was moved or deleted.'
0 commit comments