Skip to content

Commit 9a7e187

Browse files
[flutter_tools] fix Cannot delete file ENOENT from fuchsia_asset_builder (#119867)
* fix * add test
1 parent be4c8c0 commit 9a7e187

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/flutter_tools/lib/src/base/config.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ class Config {
116116
if (managed) {
117117
rethrow;
118118
} else {
119-
_file.deleteSync();
119+
try {
120+
_file.deleteSync();
121+
} on FileSystemException {
122+
// ignore
123+
}
120124
}
121125
} on Exception catch (err) {
122126
_logger

packages/flutter_tools/test/general.shard/config_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ void main() {
130130
expect(bufferLogger.errorText, contains(r'sudo chown -R $(whoami) /testfile'));
131131
});
132132

133+
testWithoutContext('Config.createForTesting does not error when failing to delete a file', () {
134+
final BufferLogger bufferLogger = BufferLogger.test();
135+
136+
final FileExceptionHandler handler = FileExceptionHandler();
137+
final MemoryFileSystem fs = MemoryFileSystem.test(opHandle: handler.opHandle);
138+
final File file = fs.file('testfile')
139+
// We write invalid JSON so that we test catching a `FormatException`
140+
..writeAsStringSync('{"This is not valid JSON"');
141+
handler.addError(
142+
file,
143+
FileSystemOp.delete,
144+
const FileSystemException(
145+
"Cannot delete file, path = 'testfile' (OS Error: No such file or directory, errno = 2)",
146+
),
147+
);
148+
149+
// Should not throw a FileSystemException
150+
Config.createForTesting(file, bufferLogger);
151+
});
152+
133153
testWithoutContext('Config in home dir is used if it exists', () {
134154
memoryFileSystem.file('.flutter_example').writeAsStringSync('{"hello":"bar"}');
135155
config = Config(

0 commit comments

Comments
 (0)