Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: sdk/lib/io/file_impl.dart

Issue 46073003: Fix File.openStream where it sometimes would keep the file open. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 8fbaf038e33615ba17fa2bc865db7c0021a90d87..ee71e567597cede20a3dddcf8fbbacf24bfd7916 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -25,6 +25,7 @@ class _FileStream extends Stream<List<int>> {
// Is there a read currently in progress?
bool _readInProgress = false;
+ bool _closed = false;
// Block read but not yet send because stream is paused.
List<int> _currentBlock;
@@ -59,14 +60,21 @@ class _FileStream extends Stream<List<int>> {
}
Future _closeFile() {
- if (_readInProgress) {
+ if (_readInProgress || _closed) {
return _closeCompleter.future;
}
+ _closed = true;
+ void done() {
+ _closeCompleter.complete();
+ _controller.close();
+ }
if (_openedFile != null) {
_openedFile.close()
- .then(_closeCompleter.complete,
- onError: _closeCompleter.completeError);
+ .catchError(_controller.addError)
+ .whenComplete(done);
_openedFile = null;
+ } else {
+ done();
}
return _closeCompleter.future;
}
@@ -99,7 +107,7 @@ class _FileStream extends Stream<List<int>> {
}
if (block.length == 0) {
if (!_unsubscribed) {
- _closeFile().then((_) { _controller.close(); });
+ _closeFile();
_unsubscribed = true;
}
return;
@@ -115,7 +123,7 @@ class _FileStream extends Stream<List<int>> {
.catchError((e) {
if (!_unsubscribed) {
_controller.addError(e);
- _closeFile().then((_) { _controller.close(); });
+ _closeFile();
_unsubscribed = true;
}
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698