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

Unified Diff: runtime/bin/file_impl.dart

Issue 9346015: Change file opening operation to set position at the end of the file when FileMode.APPEND is used. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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
Index: runtime/bin/file_impl.dart
===================================================================
--- runtime/bin/file_impl.dart (revision 3943)
+++ runtime/bin/file_impl.dart (working copy)
@@ -49,8 +49,8 @@
class _FileOutputStream implements OutputStream {
- _FileOutputStream(File file) {
- _file = file.openSync(FileMode.WRITE);
+ _FileOutputStream(File file, FileMode mode) {
+ _file = file.openSync(mode);
}
bool write(List<int> buffer, [bool copyBuffer = false]) {
@@ -591,6 +591,9 @@
}
if (id != 0) {
var randomAccessFile = new _RandomAccessFile(id, _name);
+ if (mode == FileMode.APPEND) {
+ _FileUtils.setPosition(id, _FileUtils.length(id));
Mads Ager (google) 2012/02/07 08:37:31 Please do this in the C++ code instead. Here you a
ricow1 2012/02/07 09:16:22 Done, I placed these in the platform specific file
+ }
handler(randomAccessFile);
} else if (_errorHandler != null) {
_errorHandler("Cannot open file: $_name");
@@ -615,6 +618,9 @@
if (id == 0) {
throw new FileIOException("Cannot open file: $_name");
}
+ if (mode == FileMode.APPEND) {
+ _FileUtils.setPosition(id, _FileUtils.length(id));
Mads Ager (google) 2012/02/07 08:37:31 Ditto. This is actually fine because this is the s
ricow1 2012/02/07 09:16:22 Done.
+ }
return new _RandomAccessFile(id, _name);
}
@@ -647,7 +653,14 @@
InputStream openInputStream() => new _FileInputStream(this);
- OutputStream openOutputStream() => new _FileOutputStream(this);
+ OutputStream openOutputStream([FileMode mode = FileMode.WRITE]) {
+ if (mode != FileMode.WRITE &&
+ mode != FileMode.APPEND) {
+ throw new FileIOException(
+ "Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND");
+ }
+ return new _FileOutputStream(this, mode);
+ }
String get name() => _name;

Powered by Google App Engine
This is Rietveld 408576698