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

Unified Diff: runtime/bin/file.cc

Issue 1015763002: Make sure File_WriteFrom write all data unless an error occour (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r44535 Created 5 years, 9 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: runtime/bin/file.cc
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
index c4c417b8603351b6e2526410c3cef8f9d267de06..715f7223f27f1cd0a27a9e6d1bac32153e9bbdc3 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -266,16 +266,26 @@ void FUNCTION_NAME(File_WriteFrom)(Dart_NativeArguments args) {
ASSERT(end <= buffer_len);
ASSERT(buffer != NULL);
- // Write the data out into the file.
- int64_t bytes_written = file->Write(buffer, length);
+ // Write all the data out into the file.
+ int64_t remaining = length;
+ while (remaining > 0) {
+ int64_t written = file->Write(buffer, remaining);
Anders Johnsen 2015/03/18 10:11:13 Use file->WriteFully instead?
Søren Gjesse 2015/03/19 10:12:44 Forgot about that. Done.
+ if (written < 0) {
+ break;
+ }
+ remaining -= written;
+ buffer = reinterpret_cast<uint8_t*>(buffer) + written;
+ }
// Release the direct pointer acquired above.
result = Dart_TypedDataReleaseData(buffer_obj);
if (Dart_IsError(result)) Dart_PropagateError(result);
- if (bytes_written != length) {
+ if (remaining > 0) {
Dart_Handle err = DartUtils::NewDartOSError();
if (Dart_IsError(err)) Dart_PropagateError(err);
Dart_SetReturnValue(args, err);
+ } else {
+ Dart_SetReturnValue(args, Dart_Null());
}
}
« 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