diff options
author | Tao Bao <tbao@google.com> | 2016-11-01 22:30:20 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-01 22:30:20 +0100 |
commit | bc48de6bf094a7808c5a3e447fb9840cd33ef590 (patch) | |
tree | b78f8be8fca900c7d8e2cf361b917852eec9fb3e /applypatch | |
parent | Merge "Revert "Some cleanups to recovery."" (diff) | |
parent | Merge "applypatch: Switch the parameter of Value** to std::vector." (diff) | |
download | android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.tar android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.tar.gz android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.tar.bz2 android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.tar.lz android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.tar.xz android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.tar.zst android_bootable_recovery-bc48de6bf094a7808c5a3e447fb9840cd33ef590.zip |
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/applypatch.cpp | 16 | ||||
-rw-r--r-- | applypatch/include/applypatch/applypatch.h | 15 | ||||
-rw-r--r-- | applypatch/main.cpp | 15 |
3 files changed, 23 insertions, 23 deletions
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<std::string>& patch_sha1_str, - Value** patch_data, - Value* bonus_data) { + const std::vector<std::unique_ptr<Value>>& 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 <stdint.h> #include <sys/stat.h> +#include <memory> #include <string> #include <vector> -#include "openssl/sha.h" +#include <openssl/sha.h> + #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<std::string>& patch_sha1_str, - Value** patch_data, - Value* bonus_data); + const std::vector<std::unique_ptr<Value>>& patch_data, + const Value* bonus_data); int applypatch_check(const char* filename, const std::vector<std::string>& 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<std::string>& 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 <string> #include <vector> +#include <openssl/sha.h> + #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<Value> patches; - std::vector<Value*> patch_ptrs; + + std::vector<std::unique_ptr<Value>> 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<Value>( + 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 |