From 1f672c24a39a0d7efe24619b47c356736ecce49a Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Thu, 27 Jun 2024 13:39:14 -0700 Subject: [PATCH] [tool] make the `systemTempDirectory` getter on `ErrorHandlingFileSystem` wrap the underlying filesystem's temp directory in a`ErrorHandlingDirectory` (#150876) Fixes https://github.com/flutter/flutter/issues/150730 If you can think of a more concise title, be my guest. --- .../lib/src/base/error_handling_io.dart | 5 +++ .../base/error_handling_io_test.dart | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/flutter_tools/lib/src/base/error_handling_io.dart b/packages/flutter_tools/lib/src/base/error_handling_io.dart index e1d8c4b66e..463594e0b7 100644 --- a/packages/flutter_tools/lib/src/base/error_handling_io.dart +++ b/packages/flutter_tools/lib/src/base/error_handling_io.dart @@ -122,6 +122,11 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem { } } + @override + Directory get systemTempDirectory { + return directory(delegate.systemTempDirectory); + } + @override File file(dynamic path) => ErrorHandlingFile( platform: _platform, diff --git a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart index f6a56a58d6..bc34665541 100644 --- a/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart +++ b/packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart @@ -884,6 +884,43 @@ void main() { }); }); + testWithoutContext("ErrorHandlingFileSystem.systemTempDirectory wraps delegates filesystem's systemTempDirectory", () { + final FileExceptionHandler exceptionHandler = FileExceptionHandler(); + + final MemoryFileSystem delegate = MemoryFileSystem.test( + style: FileSystemStyle.windows, + opHandle: exceptionHandler.opHandle, + ); + + final FileSystem fs = ErrorHandlingFileSystem( + delegate: delegate, + platform: FakePlatform(operatingSystem: 'windows'), + ); + + expect(fs.systemTempDirectory, isA()); + expect(fs.systemTempDirectory.path, delegate.systemTempDirectory.path); + + final File tempFile = delegate.systemTempDirectory.childFile('hello') + ..createSync(recursive: true); + + exceptionHandler.addError( + tempFile, + FileSystemOp.write, + FileSystemException( + 'Oh no!', + tempFile.path, + const OSError('Access denied ):', 5), + ), + ); + + expect( + () => fs.file(tempFile.path).writeAsStringSync('world'), + throwsToolExit(message: r''' +Flutter failed to write to a file at "C:\.tmp_rand0\hello". The flutter tool cannot access the file or directory. +Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.'''), + ); + }); + group('ProcessManager on windows throws tool exit', () { const int kDeviceFull = 112; const int kUserMappedSectionOpened = 1224;