Switch FileWriter::Write to boolean result code.
FileWriter::Write returned either the number of bytes written, or a negative
error code. No clients were doing anything with the result other than checking
for success or failure, and many clients were considering any non-zero result
success.
So, I changed the API to return less information, but just the information the
clients needed. Success or failure.
BUG=chromium-os:8521
TEST=Unittests
Change-Id: I51513d6aa7b704dc27fb90d5fae4dc7118a3f86c
Reviewed-on: https://gerrit.chromium.org/gerrit/11532
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Commit-Ready: Don Garrett <dgarrett@chromium.org>
diff --git a/delta_performer.cc b/delta_performer.cc
index 0e49df7..66c23d4 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -232,11 +232,9 @@
}
-// Wrapper around write. Returns bytes written on success or
-// -errno on error.
-// This function performs as many actions as it can, given the amount of
-// data received thus far.
-ssize_t DeltaPerformer::Write(const void* bytes, size_t count) {
+// Wrapper around write. Returns true if all requested bytes
+// were written, or false on any error, reguardless of progress.
+bool DeltaPerformer::Write(const void* bytes, size_t count) {
const char* c_bytes = reinterpret_cast<const char*>(bytes);
buffer_.insert(buffer_.end(), c_bytes, c_bytes + count);
@@ -245,10 +243,10 @@
&manifest_,
&manifest_metadata_size_);
if (result == kMetadataParseError) {
- return -EINVAL;
+ return false;
}
if (result == kMetadataParseInsufficientData) {
- return count;
+ return true;
}
// Remove protobuf and header info from buffer_, so buffer_ contains
// just data blobs
@@ -260,7 +258,7 @@
LogPartitionInfo(manifest_);
if (!PrimeUpdateState()) {
LOG(ERROR) << "Unable to prime the update state.";
- return -EINVAL;
+ return false;
}
}
ssize_t total_operations = manifest_.install_operations_size() +
@@ -289,25 +287,25 @@
if (!PerformReplaceOperation(op, is_kernel_partition)) {
LOG(ERROR) << "Failed to perform replace operation "
<< next_operation_num_;
- return -EINVAL;
+ return false;
}
} else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE) {
if (!PerformMoveOperation(op, is_kernel_partition)) {
LOG(ERROR) << "Failed to perform move operation "
<< next_operation_num_;
- return -EINVAL;
+ return false;
}
} else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_BSDIFF) {
if (!PerformBsdiffOperation(op, is_kernel_partition)) {
LOG(ERROR) << "Failed to perform bsdiff operation "
<< next_operation_num_;
- return -EINVAL;
+ return false;
}
}
next_operation_num_++;
CheckpointUpdateProgress();
}
- return count;
+ return true;
}
bool DeltaPerformer::CanPerformInstallOperation(