[tool] make the systemTempDirectory getter on ErrorHandlingFileSystem wrap the underlying filesystem's temp directory in aErrorHandlingDirectory (#150876)

Fixes https://github.com/flutter/flutter/issues/150730

If you can think of a more concise title, be my guest.
This commit is contained in:
Andrew Kolos
2024-06-27 13:39:14 -07:00
committed by GitHub
parent 74688cea3d
commit 1f672c24a3
2 changed files with 42 additions and 0 deletions

View File

@@ -122,6 +122,11 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
}
}
@override
Directory get systemTempDirectory {
return directory(delegate.systemTempDirectory);
}
@override
File file(dynamic path) => ErrorHandlingFile(
platform: _platform,

View File

@@ -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<ErrorHandlingDirectory>());
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;