Return ErrorHandlingFileSystem backed objects in ErrorHandlingFileSystem file/directory APIs (#112673)

This commit is contained in:
Jason Simmons 2022-09-29 15:57:20 -07:00 committed by GitHub
parent dd0ecc2369
commit 2a4adab7f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 18 deletions

View File

@ -119,21 +119,21 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
@override @override
File file(dynamic path) => ErrorHandlingFile( File file(dynamic path) => ErrorHandlingFile(
platform: _platform, platform: _platform,
fileSystem: delegate, fileSystem: this,
delegate: delegate.file(path), delegate: delegate.file(path),
); );
@override @override
Directory directory(dynamic path) => ErrorHandlingDirectory( Directory directory(dynamic path) => ErrorHandlingDirectory(
platform: _platform, platform: _platform,
fileSystem: delegate, fileSystem: this,
delegate: delegate.directory(path), delegate: delegate.directory(path),
); );
@override @override
Link link(dynamic path) => ErrorHandlingLink( Link link(dynamic path) => ErrorHandlingLink(
platform: _platform, platform: _platform,
fileSystem: delegate, fileSystem: this,
delegate: delegate.link(path), delegate: delegate.link(path),
); );
@ -173,7 +173,7 @@ class ErrorHandlingFile
final io.File delegate; final io.File delegate;
@override @override
final FileSystem fileSystem; final ErrorHandlingFileSystem fileSystem;
final Platform _platform; final Platform _platform;
@ -388,7 +388,7 @@ class ErrorHandlingDirectory
final io.Directory delegate; final io.Directory delegate;
@override @override
final FileSystem fileSystem; final ErrorHandlingFileSystem fileSystem;
final Platform _platform; final Platform _platform;
@ -413,20 +413,20 @@ class ErrorHandlingDirectory
delegate: delegate, delegate: delegate,
); );
// For the childEntity methods, we first obtain an instance of the entity
// from the underlying file system, then invoke childEntity() on it, then
// wrap in the ErrorHandling version.
@override @override
Directory childDirectory(String basename) => Directory childDirectory(String basename) {
wrapDirectory(fileSystem.directory(delegate).childDirectory(basename)); return fileSystem.directory(fileSystem.path.join(path, basename));
}
@override @override
File childFile(String basename) => File childFile(String basename) {
wrapFile(fileSystem.directory(delegate).childFile(basename)); return fileSystem.file(fileSystem.path.join(path, basename));
}
@override @override
Link childLink(String basename) => Link childLink(String basename) {
wrapLink(fileSystem.directory(delegate).childLink(basename)); return fileSystem.link(fileSystem.path.join(path, basename));
}
@override @override
void createSync({bool recursive = false}) { void createSync({bool recursive = false}) {
@ -527,7 +527,7 @@ class ErrorHandlingLink
final io.Link delegate; final io.Link delegate;
@override @override
final FileSystem fileSystem; final ErrorHandlingFileSystem fileSystem;
final Platform _platform; final Platform _platform;

View File

@ -1167,7 +1167,7 @@ void main() {
); );
const String expectedMessage = const String expectedMessage =
'Flutter failed to copy source to dest due to destination location error.\n' 'Flutter failed to create file at "dest".\n'
'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.'; 'Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.';
expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit(message: expectedMessage)); expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit(message: expectedMessage));
}); });

View File

@ -117,9 +117,10 @@ void main() {
testWithoutContext('Config does not error on a normally fatal file system exception', () { testWithoutContext('Config does not error on a normally fatal file system exception', () {
final BufferLogger bufferLogger = BufferLogger.test(); final BufferLogger bufferLogger = BufferLogger.test();
final Platform platform = FakePlatform();
final File file = ErrorHandlingFile( final File file = ErrorHandlingFile(
platform: FakePlatform(), platform: platform,
fileSystem: MemoryFileSystem.test(), fileSystem: ErrorHandlingFileSystem(delegate: MemoryFileSystem.test(), platform: platform),
delegate: FakeFile('testfile'), delegate: FakeFile('testfile'),
); );