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

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

Issue 15337005: Ensure to close file-stream on all errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 2057234ac7af8da9ca6804232adac3834fb75a92..a7c145099f8eb3cb6d1eaf38d13d9b5d7a2d806e 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -76,7 +76,12 @@ class _FileStream extends Stream<List<int>> {
if (_end != null) {
readBytes = min(readBytes, _end - _position);
if (readBytes < 0) {
- throw new RangeError("Bad end position: $_end");
+ if (!_unsubscribed) {
+ _controller.addError(new RangeError("Bad end position: $_end"));
+ _closeFile().then((_) { _controller.close(); });
kustermann 2013/05/21 11:23:57 I don't know if the Future returned by '_closeFile
Anders Johnsen 2013/05/21 11:37:27 I'm quite sure it can't. Can't come to think of an
+ _unsubscribed = true;
+ }
+ return;
}
}
_openedFile.read(readBytes)
@@ -107,6 +112,13 @@ class _FileStream extends Stream<List<int>> {
}
void _start() {
+ if (_position == null) {
+ _position = 0;
+ } else if (_position < 0) {
+ _controller.addError(new RangeError("Bad start position: $_position"));
+ _controller.close();
+ return;
+ }
Future<RandomAccessFile> openFuture;
if (_path != null) {
openFuture = new File(_path).open(mode: FileMode.READ);
@@ -116,13 +128,8 @@ class _FileStream extends Stream<List<int>> {
openFuture
.then((RandomAccessFile opened) {
_openedFile = opened;
- if (_position == null) {
- _position = 0;
- }
if (_position > 0) {
return opened.setPosition(_position);
- } else if (_position < 0) {
- throw new RangeError("Bad start position: $_position");
}
})
.then((_) => _readBlock())
« 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