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

Unified Diff: omaha_hash_calculator.cc

Issue 3588015: AU: Include the old/new kernel/rootfs size/hash in the update metadata. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: no need to close negative handles Created 10 years, 2 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 | « omaha_hash_calculator.h ('k') | omaha_hash_calculator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: omaha_hash_calculator.cc
diff --git a/omaha_hash_calculator.cc b/omaha_hash_calculator.cc
index bc7147602abefe4e39407063654f4722576e8802..bab82fb43b9bcaa39856b1cc28121c25a277bf2e 100644
--- a/omaha_hash_calculator.cc
+++ b/omaha_hash_calculator.cc
@@ -4,10 +4,14 @@
#include "update_engine/omaha_hash_calculator.h"
+#include <fcntl.h>
+
+#include <base/eintr_wrapper.h>
+#include <base/logging.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
-#include "base/logging.h"
+
#include "update_engine/utils.h"
using std::string;
@@ -31,6 +35,34 @@ bool OmahaHashCalculator::Update(const char* data, size_t length) {
return true;
}
+off_t OmahaHashCalculator::UpdateFile(const string& name, off_t length) {
+ int fd = HANDLE_EINTR(open(name.c_str(), O_RDONLY));
+ if (fd < 0) {
+ return -1;
+ }
+
+ const int kBufferSize = 128 * 1024; // 128 KiB
+ vector<char> buffer(kBufferSize);
+ off_t bytes_processed = 0;
+ while (length < 0 || bytes_processed < length) {
+ off_t bytes_to_read = buffer.size();
+ if (length >= 0 && bytes_to_read > length - bytes_processed) {
+ bytes_to_read = length - bytes_processed;
+ }
+ ssize_t rc = HANDLE_EINTR(read(fd, &buffer[0], bytes_to_read));
adlr 2010/10/08 01:21:58 I never heard of HANDLE_EINTR and just looked it u
petkov 2010/10/08 04:14:29 open/read/close can theoretically (but somewhat un
+ if (rc == 0) { // EOF
+ break;
+ }
+ if (rc < 0 || !Update(&buffer[0], rc)) {
+ bytes_processed = -1;
+ break;
+ }
+ bytes_processed += rc;
+ }
+ HANDLE_EINTR(close(fd));
+ return bytes_processed;
+}
+
// Call Finalize() when all data has been passed in. This mostly just
// calls OpenSSL's SHA256_Final() and then base64 encodes the hash.
bool OmahaHashCalculator::Finalize() {
« no previous file with comments | « omaha_hash_calculator.h ('k') | omaha_hash_calculator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698