[flutter_tools] fix Cannot delete file ENOENT from fuchsia_asset_builder (#119867)

* fix

* add test
This commit is contained in:
Christopher Fujino 2023-02-03 11:24:41 -08:00 committed by GitHub
parent be4c8c0eb1
commit 9a7e18701e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -116,7 +116,11 @@ class Config {
if (managed) {
rethrow;
} else {
_file.deleteSync();
try {
_file.deleteSync();
} on FileSystemException {
// ignore
}
}
} on Exception catch (err) {
_logger

View File

@ -130,6 +130,26 @@ void main() {
expect(bufferLogger.errorText, contains(r'sudo chown -R $(whoami) /testfile'));
});
testWithoutContext('Config.createForTesting does not error when failing to delete a file', () {
final BufferLogger bufferLogger = BufferLogger.test();
final FileExceptionHandler handler = FileExceptionHandler();
final MemoryFileSystem fs = MemoryFileSystem.test(opHandle: handler.opHandle);
final File file = fs.file('testfile')
// We write invalid JSON so that we test catching a `FormatException`
..writeAsStringSync('{"This is not valid JSON"');
handler.addError(
file,
FileSystemOp.delete,
const FileSystemException(
"Cannot delete file, path = 'testfile' (OS Error: No such file or directory, errno = 2)",
),
);
// Should not throw a FileSystemException
Config.createForTesting(file, bufferLogger);
});
testWithoutContext('Config in home dir is used if it exists', () {
memoryFileSystem.file('.flutter_example').writeAsStringSync('{"hello":"bar"}');
config = Config(