diff options
author | Sen Jiang <senj@google.com> | 2015-11-24 21:32:23 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-11-24 21:32:23 +0000 |
commit | 0fc620f2501b5e40fb590c6820436490a6b8f369 (patch) | |
tree | 8bbc34633412bb4be3cf55ae708e8fc1ad2651c2 | |
parent | a1e219f52f03542c107a6a7c0bb4a2d119bfc7b3 (diff) | |
parent | a1e8251cad073f210d86a3e99b166b75409891fc (diff) | |
download | bsdiff-0fc620f2501b5e40fb590c6820436490a6b8f369.tar.gz |
Merge "Various fixes in bspatch and File class."
am: a1e8251cad
* commit 'a1e8251cad073f210d86a3e99b166b75409891fc':
Various fixes in bspatch and File class.
-rw-r--r-- | bspatch.cc | 18 | ||||
-rw-r--r-- | file.cc | 7 |
2 files changed, 14 insertions, 11 deletions
@@ -175,6 +175,7 @@ int bspatch( // The oldpos can be negative, but the new pos is only incremented linearly. int64_t oldpos = 0; uint64_t newpos = 0; + std::vector<u_char> old_buf(1024 * 1024); while (newpos < newsize) { int64_t i, j; // Read control data. @@ -215,15 +216,15 @@ int bspatch( uint64_t chunk_size = old_file_pos - i; while (chunk_size > 0) { size_t read_bytes; - size_t bytes_to_read = std::min( - chunk_size, - static_cast<uint64_t>(std::numeric_limits<size_t>::max())); - if (!old_file->Read(new_buf + j, bytes_to_read, &read_bytes)) { + size_t bytes_to_read = + std::min(chunk_size, static_cast<uint64_t>(old_buf.size())); + if (!old_file->Read(old_buf.data(), bytes_to_read, &read_bytes)) err(1, "error reading from input file"); - } if (!read_bytes) errx(1, "EOF reached while reading from input file"); - j += read_bytes; + // new_buf already has data from diff block, adds old data to it. + for (size_t k = 0; k < read_bytes; k++) + new_buf[j++] += old_buf[k]; chunk_size -= read_bytes; } @@ -269,12 +270,13 @@ int bspatch( new_file.reset(new ExtentsFile(std::move(new_file), parsed_new_extents)); } + u_char* temp_new_buf = new_buf; // new_buf needed for free() while (newsize > 0) { size_t bytes_written; - if (!new_file->Write(new_buf, newsize, &bytes_written)) + if (!new_file->Write(temp_new_buf, newsize, &bytes_written)) err(1, "Error writing new file %s", new_filename); newsize -= bytes_written; - new_buf += bytes_written; + temp_new_buf += bytes_written; } if (!new_file->Close()) @@ -25,7 +25,7 @@ namespace bsdiff { std::unique_ptr<File> File::FOpen(const char* pathname, int flags) { - int fd = TEMP_FAILURE_RETRY(open(pathname, flags)); + int fd = TEMP_FAILURE_RETRY(open(pathname, flags, 0644)); if (fd < 0) return std::unique_ptr<File>(); return std::unique_ptr<File>(new File(fd)); @@ -69,7 +69,7 @@ bool File::Seek(off_t pos) { errno = EOVERFLOW; return false; } - off_t newpos = lseek(fd_, pos, SEEK_SET) == pos; + off_t newpos = lseek(fd_, pos, SEEK_SET); if (newpos < 0) return false; if (newpos != pos) { @@ -96,7 +96,8 @@ bool File::GetSize(uint64_t* size) { if (fstat(fd_, &stbuf) == -1) return false; if (S_ISREG(stbuf.st_mode)) { - return stbuf.st_size; + *size = stbuf.st_size; + return true; } if (S_ISBLK(stbuf.st_mode)) { #if defined(BLKGETSIZE64) |