mirror of
https://github.com/expo/bsdiff.git
synced 2026-11-14 17:49:03 -10:00
Merge "Various fixes in bspatch and File class."
This commit is contained in:
commit
a1e8251cad
2 files changed
+14
-11
No files matched your search
+10
-8
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user