[io] Calling flush after close on File.open's IOSync should not throw an exception
The documentation of IOSync states that calling flush on a closed IOSink may have no effect: https://github.com/dart-lang/sdk/blob/main/sdk/lib/io/io_sink.dart#L109 The future returned by close in the new implementation does not complete until after a call to flush has completed. The previous implementation of File.open did not throw when calling flush after close. CoreLibraryReviewExempt: IO only, restoring previous semantics Bug: b/274405250 Change-Id: I56bbe02e886085cc8156e60264f5b77593c8a075 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289823 Reviewed-by: Emmanuel Pellereau <emmanuelp@google.com>
This commit is contained in:
@@ -439,7 +439,7 @@ class _RandomAccessFileIOSync implements IOSink {
|
||||
|
||||
Future<File?> flush() {
|
||||
if (_isClosed) {
|
||||
throw StateError("${_file?.path ?? "IOSink"} is closed");
|
||||
return done;
|
||||
}
|
||||
if (_isBound) {
|
||||
throw StateError("${_file?.path ?? "IOSink"} is bound to a stream");
|
||||
|
||||
@@ -392,13 +392,8 @@ Future<void> testFlushDuringClose(Directory tmpDir) async {
|
||||
final sink = file.openWrite();
|
||||
final close = sink.close();
|
||||
|
||||
try {
|
||||
await sink.flush();
|
||||
} on StateError catch (e) {
|
||||
Expect.contains('flush_during_close is closed', e.message);
|
||||
}
|
||||
|
||||
await close;
|
||||
Expect.equals(file, await sink.flush());
|
||||
Expect.equals(file, await close);
|
||||
}
|
||||
|
||||
Future<void> testFailedWrite(Directory tmpDir) async {
|
||||
|
||||
@@ -394,13 +394,8 @@ Future<void> testFlushDuringClose(Directory tmpDir) async {
|
||||
final sink = file.openWrite();
|
||||
final close = sink.close();
|
||||
|
||||
try {
|
||||
await sink.flush();
|
||||
} on StateError catch (e) {
|
||||
Expect.contains('flush_during_close is closed', e.message);
|
||||
}
|
||||
|
||||
await close;
|
||||
Expect.equals(file, await sink.flush());
|
||||
Expect.equals(file, await close);
|
||||
}
|
||||
|
||||
Future<void> testFailedWrite(Directory tmpDir) async {
|
||||
|
||||
Reference in New Issue
Block a user