From fada91ccf2b31d69d72899388b1833186d763d1a Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 27 Oct 2016 18:16:06 -0700 Subject: applypatch: Switch the parameter of Value** to std::vector. Test: Unit tests and install-recovery.sh pass on angler and dragon. Change-Id: I328e6554edca667cf850f5584ebf1ac211e3d4d1 --- applypatch/applypatch.cpp | 16 ++++++++-------- applypatch/include/applypatch/applypatch.h | 15 ++++++++------- applypatch/main.cpp | 15 +++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'applypatch') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 48e4c8386..9d505f9f6 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -530,8 +530,8 @@ int applypatch(const char* source_filename, const char* target_sha1_str, size_t target_size, const std::vector& patch_sha1_str, - Value** patch_data, - Value* bonus_data) { + const std::vector>& patch_data, + const Value* bonus_data) { printf("patch %s: ", source_filename); if (target_filename[0] == '-' && target_filename[1] == '\0') { @@ -546,8 +546,8 @@ int applypatch(const char* source_filename, FileContents copy_file; FileContents source_file; - const Value* source_patch_value = NULL; - const Value* copy_patch_value = NULL; + const Value* source_patch_value = nullptr; + const Value* copy_patch_value = nullptr; // We try to load the target file into the source_file object. if (LoadFileContents(target_filename, &source_file) == 0) { @@ -571,11 +571,11 @@ int applypatch(const char* source_filename, if (!source_file.data.empty()) { int to_use = FindMatchingPatch(source_file.sha1, patch_sha1_str); if (to_use >= 0) { - source_patch_value = patch_data[to_use]; + source_patch_value = patch_data[to_use].get(); } } - if (source_patch_value == NULL) { + if (source_patch_value == nullptr) { source_file.data.clear(); printf("source file is bad; trying copy\n"); @@ -587,10 +587,10 @@ int applypatch(const char* source_filename, int to_use = FindMatchingPatch(copy_file.sha1, patch_sha1_str); if (to_use >= 0) { - copy_patch_value = patch_data[to_use]; + copy_patch_value = patch_data[to_use].get(); } - if (copy_patch_value == NULL) { + if (copy_patch_value == nullptr) { // fail. printf("copy file doesn't match source SHA-1s either\n"); return 1; diff --git a/applypatch/include/applypatch/applypatch.h b/applypatch/include/applypatch/applypatch.h index 80d681638..ca3dafbc9 100644 --- a/applypatch/include/applypatch/applypatch.h +++ b/applypatch/include/applypatch/applypatch.h @@ -20,10 +20,12 @@ #include #include +#include #include #include -#include "openssl/sha.h" +#include + #include "edify/expr.h" struct FileContents { @@ -41,27 +43,26 @@ struct FileContents { typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*); -// applypatch.c +// applypatch.cpp int ShowLicenses(); size_t FreeSpaceForFile(const char* filename); int CacheSizeCheck(size_t bytes); int ParseSha1(const char* str, uint8_t* digest); -int applypatch_flash(const char* source_filename, const char* target_filename, - const char* target_sha1_str, size_t target_size); int applypatch(const char* source_filename, const char* target_filename, const char* target_sha1_str, size_t target_size, const std::vector& patch_sha1_str, - Value** patch_data, - Value* bonus_data); + const std::vector>& patch_data, + const Value* bonus_data); int applypatch_check(const char* filename, const std::vector& patch_sha1_str); +int applypatch_flash(const char* source_filename, const char* target_filename, + const char* target_sha1_str, size_t target_size); int LoadFileContents(const char* filename, FileContents* file); int SaveFileContents(const char* filename, const FileContents* file); -void FreeFileContents(FileContents* file); int FindMatchingPatch(uint8_t* sha1, const std::vector& patch_sha1_str); // bsdiff.cpp diff --git a/applypatch/main.cpp b/applypatch/main.cpp index 294f7ee21..988b6f9b1 100644 --- a/applypatch/main.cpp +++ b/applypatch/main.cpp @@ -23,9 +23,10 @@ #include #include +#include + #include "applypatch/applypatch.h" #include "edify/expr.h" -#include "openssl/sha.h" static int CheckMode(int argc, char** argv) { if (argc < 3) { @@ -129,15 +130,13 @@ static int PatchMode(int argc, char** argv) { printf("failed to parse patch args\n"); return 1; } - std::vector patches; - std::vector patch_ptrs; + + std::vector> patches; for (size_t i = 0; i < files.size(); ++i) { - patches.push_back(Value(VAL_BLOB, - std::string(files[i].data.cbegin(), files[i].data.cend()))); - patch_ptrs.push_back(&patches[i]); + patches.push_back(std::make_unique( + VAL_BLOB, std::string(files[i].data.cbegin(), files[i].data.cend()))); } - return applypatch(argv[1], argv[2], argv[3], target_size, - sha1s, patch_ptrs.data(), &bonus); + return applypatch(argv[1], argv[2], argv[3], target_size, sha1s, patches, &bonus); } // This program applies binary patches to files in a way that is safe -- cgit v1.2.3