[tool] make ErrorHandlingFileSystem.deleteIfExists catch error code 3 (ERROR_PATH_NOT_FOUND on Windows) (#150741)

Resolves https://github.com/flutter/flutter/issues/150736

FYI I plan to cherry-pick this
This commit is contained in:
Andrew Kolos
2024-06-25 09:24:04 -07:00
committed by GitHub
parent e726eb401c
commit d520f07647
2 changed files with 39 additions and 13 deletions

View File

@@ -98,6 +98,24 @@ void main() {
}, throwsFileSystemException());
});
testWithoutContext('deleteIfExists throws tool exit if the path is not found on Windows', () {
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
platform: windowsPlatform,
);
final File file = fileSystem.file(fileSystem.path.join('directory', 'file'))
..createSync(recursive: true);
exceptionHandler.addError(
file,
FileSystemOp.delete,
FileSystemException('', file.path, const OSError('', 2)),
);
expect(() => ErrorHandlingFileSystem.deleteIfExists(file), throwsToolExit());
});
group('throws ToolExit on Windows', () {
const int kDeviceFull = 112;
const int kUserMappedSectionOpened = 1224;
@@ -571,14 +589,14 @@ void main() {
testWithoutContext('When the current working directory disappears', () async {
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: ThrowsOnCurrentDirectoryFileSystem(kSystemCannotFindFile),
delegate: ThrowsOnCurrentDirectoryFileSystem(kSystemCodeCannotFindFile),
platform: linuxPlatform,
);
expect(() => fileSystem.currentDirectory, throwsToolExit(message: 'Unable to read current working directory'));
});
testWithoutContext('Rethrows os error $kSystemCannotFindFile', () {
testWithoutContext('Rethrows os error $kSystemCodeCannotFindFile', () {
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
platform: linuxPlatform,
@@ -588,11 +606,11 @@ void main() {
exceptionHandler.addError(
file,
FileSystemOp.read,
FileSystemException('', file.path, const OSError('', kSystemCannotFindFile)),
FileSystemException('', file.path, const OSError('', kSystemCodeCannotFindFile)),
);
// Error is not caught by other operations.
expect(() => fileSystem.file('foo').readAsStringSync(), throwsFileSystemException(kSystemCannotFindFile));
expect(() => fileSystem.file('foo').readAsStringSync(), throwsFileSystemException(kSystemCodeCannotFindFile));
});
});