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() { |