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;