am 63177cbf: Merge "Use base::WriteFully in zip_archive."

* commit '63177cbf7cd1787bf4c5f0ba4a824d1a13e6eeb3':
  Use base::WriteFully in zip_archive.
This commit is contained in:
Narayan Kamath 2015-04-29 14:57:19 +00:00 committed by Android Git Automerger
commit ccb8abf5de
2 changed files with 9 additions and 17 deletions

View file

@ -58,7 +58,8 @@ LOCAL_STATIC_LIBRARIES := \
libsparse_host \ libsparse_host \
libutils \ libutils \
liblog \ liblog \
libz libz \
libbase
ifneq ($(HOST_OS),windows) ifneq ($(HOST_OS),windows)
LOCAL_STATIC_LIBRARIES += libselinux LOCAL_STATIC_LIBRARIES += libselinux

View file

@ -30,6 +30,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "base/file.h"
#include "base/macros.h" // TEMP_FAILURE_RETRY may or may not be in unistd #include "base/macros.h" // TEMP_FAILURE_RETRY may or may not be in unistd
#include "base/memory.h" #include "base/memory.h"
#include "log/log.h" #include "log/log.h"
@ -1033,24 +1034,14 @@ class FileWriter : public Writer {
return false; return false;
} }
// Keep track of the start position so we can calculate the const bool result = android::base::WriteFully(fd_, buf, buf_size);
// total number of bytes written. if (result) {
const uint8_t* const start = buf; total_bytes_written_ += buf_size;
while (buf_size > 0) { } else {
ssize_t bytes_written = TEMP_FAILURE_RETRY(write(fd_, buf, buf_size)); ALOGW("Zip: unable to write " ZD " bytes to file; %s", buf_size, strerror(errno));
if (bytes_written == -1) {
ALOGW("Zip: unable to write " ZD " bytes to file; %s", buf_size, strerror(errno));
return false;
}
buf_size -= bytes_written;
buf += bytes_written;
} }
total_bytes_written_ += static_cast<size_t>( return result;
reinterpret_cast<uintptr_t>(buf) - reinterpret_cast<uintptr_t>(start));
return true;
} }
private: private:
FileWriter(const int fd, const size_t declared_length) : FileWriter(const int fd, const size_t declared_length) :