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

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

Issue 24667003: Fix File stream on cancel. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 3 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 | tests/standalone/standalone.status » ('j') | 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 c9bfb8cc33384944d3c59e0dc04a4534fc66c745..1dce796efc46c74f6049a15b331138c286971bf2 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -17,6 +17,7 @@ class _FileStream extends Stream<List<int>> {
RandomAccessFile _openedFile;
int _position;
int _end;
+ final Completer _closeCompleter = new Completer();
// Has the stream been paused or unsubscribed?
bool _paused = false;
@@ -58,14 +59,16 @@ class _FileStream extends Stream<List<int>> {
}
Future _closeFile() {
- Future closeFuture;
+ if (_readInProgress) {
+ return _closeCompleter.future;
+ }
if (_openedFile != null) {
- Future closeFuture = _openedFile.close();
+ _openedFile.close()
+ .then(_closeCompleter.complete,
+ onError: _closeCompleter.completeError);
_openedFile = null;
- return closeFuture;
- } else {
- return new Future.value();
}
+ return _closeCompleter.future;
}
void _readBlock() {
@@ -76,6 +79,7 @@ class _FileStream extends Stream<List<int>> {
if (_end != null) {
readBytes = min(readBytes, _end - _position);
if (readBytes < 0) {
+ _readInProgress = false;
if (!_unsubscribed) {
_controller.addError(new RangeError("Bad end position: $_end"));
_closeFile().then((_) { _controller.close(); });
@@ -85,8 +89,14 @@ class _FileStream extends Stream<List<int>> {
}
}
_openedFile.read(readBytes)
- .then((block) {
+ .whenComplete(() {
_readInProgress = false;
+ })
+ .then((block) {
+ if (_unsubscribed) {
+ _closeFile();
+ return;
+ }
if (block.length == 0) {
if (!_unsubscribed) {
_closeFile().then((_) { _controller.close(); });
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698