summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
authorsorin@chromium.org <sorin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-21 20:41:36 +0000
committersorin@chromium.org <sorin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-21 20:41:36 +0000
commite3e696d3e883f38577252e1a1a6a98ae89dea079 (patch)
treeb5adbe01ec71c10c5f2d37bff9161acc40da2455 /courgette
parent0ad74fd43800b179bc3d50847f695d4a902c79ca (diff)
downloadchromium_src-e3e696d3e883f38577252e1a1a6a98ae89dea079.zip
chromium_src-e3e696d3e883f38577252e1a1a6a98ae89dea079.tar.gz
chromium_src-e3e696d3e883f38577252e1a1a6a98ae89dea079.tar.bz2
Differential updates for components. We are adding support for delivering delta updates for Chrome components. Initial platform support for the patcher is Windows only. The update response includes both the full update and, if available, the differential update. The differential update is tried first, then the full update, if needed.
BUG=245318 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=207805 Review URL: https://chromiumcodereview.appspot.com/15908002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207917 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette')
-rw-r--r--courgette/disassembler_elf_32.h14
-rw-r--r--courgette/disassembler_elf_32_x86.h5
-rw-r--r--courgette/third_party/bsdiff.h10
-rw-r--r--courgette/third_party/bsdiff_apply.cc41
4 files changed, 59 insertions, 11 deletions
diff --git a/courgette/disassembler_elf_32.h b/courgette/disassembler_elf_32.h
index 5c3f8a2..b1832dc 100644
--- a/courgette/disassembler_elf_32.h
+++ b/courgette/disassembler_elf_32.h
@@ -47,7 +47,7 @@ class DisassemblerElf32 : public Disassembler {
// Misc Section Helpers
- const Elf32_Half SectionHeaderCount() const {
+ Elf32_Half SectionHeaderCount() const {
return section_header_table_size_;
}
@@ -60,13 +60,13 @@ class DisassemblerElf32 : public Disassembler {
return OffsetToPointer(SectionHeader(id)->sh_offset);
}
- const Elf32_Word SectionBodySize(int id) const {
+ Elf32_Word SectionBodySize(int id) const {
return SectionHeader(id)->sh_size;
}
// Misc Segment Helpers
- const Elf32_Half ProgramSegmentHeaderCount() const {
+ Elf32_Half ProgramSegmentHeaderCount() const {
return program_header_table_size_;
}
@@ -76,22 +76,22 @@ class DisassemblerElf32 : public Disassembler {
}
// The virtual memory address at which this program segment will be loaded
- const Elf32_Addr ProgramSegmentMemoryBegin(int id) const {
+ Elf32_Addr ProgramSegmentMemoryBegin(int id) const {
return ProgramSegmentHeader(id)->p_vaddr;
}
// The number of virtual memory bytes for this program segment
- const Elf32_Word ProgramSegmentMemorySize(int id) const {
+ Elf32_Word ProgramSegmentMemorySize(int id) const {
return ProgramSegmentHeader(id)->p_memsz;
}
// Pointer into the source file for this program segment
- const Elf32_Addr ProgramSegmentFileOffset(int id) const {
+ Elf32_Addr ProgramSegmentFileOffset(int id) const {
return ProgramSegmentHeader(id)->p_offset;
}
// Number of file bytes for this program segment. Is <= ProgramMemorySize.
- const Elf32_Word ProgramSegmentFileSize(int id) const {
+ Elf32_Word ProgramSegmentFileSize(int id) const {
return ProgramSegmentHeader(id)->p_filesz;
}
diff --git a/courgette/disassembler_elf_32_x86.h b/courgette/disassembler_elf_32_x86.h
index 6096781..28de7cf 100644
--- a/courgette/disassembler_elf_32_x86.h
+++ b/courgette/disassembler_elf_32_x86.h
@@ -23,13 +23,12 @@ class DisassemblerElf32X86 : public DisassemblerElf32 {
virtual e_machine_values ElfEM() { return EM_386; }
protected:
-
virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
- const WARN_UNUSED_RESULT;
+ const WARN_UNUSED_RESULT;
virtual CheckBool ParseRelocationSection(
const Elf32_Shdr *section_header,
- AssemblyProgram* program) WARN_UNUSED_RESULT;
+ AssemblyProgram* program) WARN_UNUSED_RESULT;
virtual CheckBool ParseRel32RelocsFromSection(
const Elf32_Shdr* section) WARN_UNUSED_RESULT;
diff --git a/courgette/third_party/bsdiff.h b/courgette/third_party/bsdiff.h
index 5e5683a..77897a8 100644
--- a/courgette/third_party/bsdiff.h
+++ b/courgette/third_party/bsdiff.h
@@ -30,12 +30,15 @@
* 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc}
* Changed status to an enum, removed unused status codes.
* --Stephen Adams <sra@chromium.org>
+ * 2013-04-10 - Added wrapper to apply a patch directly to files.
+ * --Joshua Pawlicki <waffles@chromium.org>
*/
#ifndef COURGETTE_BSDIFF_H_
#define COURGETTE_BSDIFF_H_
#include "base/basictypes.h"
+#include "base/file_util.h"
namespace courgette {
@@ -44,7 +47,8 @@ enum BSDiffStatus {
MEM_ERROR = 1,
CRC_ERROR = 2,
READ_ERROR = 3,
- UNEXPECTED_ERROR = 4
+ UNEXPECTED_ERROR = 4,
+ WRITE_ERROR = 5
};
class SourceStream;
@@ -64,6 +68,10 @@ BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream,
SourceStream* patch_stream,
SinkStream* new_stream);
+// As above, but simply takes the file paths.
+BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_stream,
+ const base::FilePath& patch_stream,
+ const base::FilePath& new_stream);
// The following declarations are common to the patch-creation and
// patch-application code.
diff --git a/courgette/third_party/bsdiff_apply.cc b/courgette/third_party/bsdiff_apply.cc
index 762c12c..3ed346e 100644
--- a/courgette/third_party/bsdiff_apply.cc
+++ b/courgette/third_party/bsdiff_apply.cc
@@ -26,6 +26,8 @@
* Changelog:
* 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc}
* --Stephen Adams <sra@chromium.org>
+ * 2013-04-10 - Add wrapper method to apply a patch to files directly.
+ * --Joshua Pawlicki <waffles@chromium.org>
*/
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
@@ -34,6 +36,7 @@
#include "courgette/third_party/bsdiff.h"
+#include "base/files/memory_mapped_file.h"
#include "courgette/crc.h"
#include "courgette/streams.h"
@@ -168,4 +171,42 @@ BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream,
return OK;
}
+BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path,
+ const base::FilePath& patch_file_path,
+ const base::FilePath& new_file_path) {
+ // Set up the old stream.
+ base::MemoryMappedFile old_file;
+ if (!old_file.Initialize(old_file_path)) {
+ return READ_ERROR;
+ }
+ SourceStream old_file_stream;
+ old_file_stream.Init(old_file.data(), old_file.length());
+
+ // Set up the patch stream.
+ base::MemoryMappedFile patch_file;
+ if (!patch_file.Initialize(patch_file_path)) {
+ return READ_ERROR;
+ }
+ SourceStream patch_file_stream;
+ patch_file_stream.Init(patch_file.data(), patch_file.length());
+
+ // Set up the new stream and apply the patch.
+ SinkStream new_sink_stream;
+ BSDiffStatus status = ApplyBinaryPatch(&old_file_stream,
+ &patch_file_stream,
+ &new_sink_stream);
+ if (status != OK) {
+ return status;
+ }
+
+ // Write the stream to disk.
+ int written = file_util::WriteFile(
+ new_file_path,
+ reinterpret_cast<const char*>(new_sink_stream.Buffer()),
+ static_cast<int>(new_sink_stream.Length()));
+ if (written != static_cast<int>(new_sink_stream.Length()))
+ return WRITE_ERROR;
+ return OK;
+}
+
} // namespace