From d33b2f86b79573ccf73fd211d0813b2663fafd38 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 28 Sep 2017 21:29:11 -0700 Subject: otafault: Move headers under otafault/. Test: mmma bootable/recovery Change-Id: I3ceb72f703c7c2857d656c137d71baa1fccd8238 --- applypatch/applypatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 51bf3932a..729d2a910 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -39,7 +39,7 @@ #include #include "edify/expr.h" -#include "ota_io.h" +#include "otafault/ota_io.h" #include "print_sha1.h" static int LoadPartitionContents(const std::string& filename, FileContents* file); -- cgit v1.2.3 From 09e468f84cc245fba61d69165b4af8f1ec4cdfd5 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 29 Sep 2017 14:39:33 -0700 Subject: Move rangeset.h and print_sha1.h into otautil. Also drop the "bootable/recovery" path in LOCAL_C_INCLUDES from applypatch modules. Test: lunch aosp_{angler,bullhead,fugu,dragon,sailfish}-userdebug; mmma bootable/recovery Change-Id: Idd602a796894f971ee4f8fa3eafe36c42d9de986 --- applypatch/applypatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 729d2a910..c8b75df79 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -40,7 +40,7 @@ #include "edify/expr.h" #include "otafault/ota_io.h" -#include "print_sha1.h" +#include "otautil/print_sha1.h" static int LoadPartitionContents(const std::string& filename, FileContents* file); static size_t FileSink(const unsigned char* data, size_t len, int fd); -- cgit v1.2.3 From a88cc5440ed79a0927f57bbd03377ff3ce04a760 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 25 Oct 2017 13:16:54 -0700 Subject: Switch to bionic gtest in bootable/recovery We encountered segfaults in Imgdiff host tests due to the failure to reset states of getopt. The problem can be solved by switching to use bionic's gtest where a new process is forked for each test. Also modify the recovery_component_test to make sure it runs in parallel. Changes include: 1. Merge the writes to misc partition into one single test. 2. Change the hard coded location "/cache/saved.file" into a configurable variable. Bug: 67849209 Test: recovery tests pass Change-Id: I165d313f32b83393fb7922c5078636ac40b50bc2 --- applypatch/applypatch.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index c8b75df79..2153b5f19 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -42,6 +42,8 @@ #include "otafault/ota_io.h" #include "otautil/print_sha1.h" +std::string cache_temp_source = "/cache/saved.file"; + static int LoadPartitionContents(const std::string& filename, FileContents* file); static size_t FileSink(const unsigned char* data, size_t len, int fd); static int GenerateTarget(const FileContents& source_file, const std::unique_ptr& patch, @@ -411,12 +413,10 @@ int applypatch_check(const char* filename, const std::vector& patch (!patch_sha1_str.empty() && FindMatchingPatch(file.sha1, patch_sha1_str) < 0)) { printf("file \"%s\" doesn't have any of expected sha1 sums; checking cache\n", filename); - // If the source file is missing or corrupted, it might be because - // we were killed in the middle of patching it. A copy of it - // should have been made in CACHE_TEMP_SOURCE. If that file - // exists and matches the sha1 we're looking for, the check still - // passes. - if (LoadFileContents(CACHE_TEMP_SOURCE, &file) != 0) { + // If the source file is missing or corrupted, it might be because we were killed in the middle + // of patching it. A copy of it should have been made in cache_temp_source. If that file + // exists and matches the sha1 we're looking for, the check still passes. + if (LoadFileContents(cache_temp_source.c_str(), &file) != 0) { printf("failed to load cache file\n"); return 1; } @@ -539,7 +539,7 @@ int applypatch(const char* source_filename, const char* target_filename, printf("source file is bad; trying copy\n"); FileContents copy_file; - if (LoadFileContents(CACHE_TEMP_SOURCE, ©_file) < 0) { + if (LoadFileContents(cache_temp_source.c_str(), ©_file) < 0) { printf("failed to read copy file\n"); return 1; } @@ -634,7 +634,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr printf("not enough free space on /cache\n"); return 1; } - if (SaveFileContents(CACHE_TEMP_SOURCE, &source_file) < 0) { + if (SaveFileContents(cache_temp_source.c_str(), &source_file) < 0) { printf("failed to back up source file\n"); return 1; } @@ -680,7 +680,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr } // Delete the backup copy of the source. - unlink(CACHE_TEMP_SOURCE); + unlink(cache_temp_source.c_str()); // Success! return 0; -- cgit v1.2.3 From 1e0941f4f63d5ee56ad42aa3aa47eb6a8a155077 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 10 Nov 2017 11:49:53 -0800 Subject: applypatch: Change the patch parameter to const Value& in Apply{BSDiff,Image}Patch. It used to be "const Value*", but nullptr won't be a valid input. Test: recovery_host_test; recovery_component_test Change-Id: I904b5689ac3e64504088bf0544c9fb5d45a52243 --- applypatch/applypatch.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 2153b5f19..41a72eb15 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -651,11 +651,11 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr int result; if (use_bsdiff) { - result = ApplyBSDiffPatch(source_file.data.data(), source_file.data.size(), patch.get(), 0, - sink, &ctx); + result = + ApplyBSDiffPatch(source_file.data.data(), source_file.data.size(), *patch, 0, sink, &ctx); } else { - result = ApplyImagePatch(source_file.data.data(), source_file.data.size(), patch.get(), sink, - &ctx, bonus_data); + result = ApplyImagePatch(source_file.data.data(), source_file.data.size(), *patch, sink, &ctx, + bonus_data); } if (result != 0) { -- cgit v1.2.3 From 47e5a8d08569a456981854a194d6dc66b8d85265 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 1 Dec 2017 10:53:34 -0800 Subject: applypatch: Remove the 'st' field from FileContents. It used to keep track of the stat(2) info (e.g. st_mode/st_gid/st_uid) while patching a file in file-based OTA. Test: Build and use the new updater to apply an update on bullhead. Change-Id: Ibf8f0f4b14298a9489bf24a2678bb279c5d9c8f3 --- applypatch/applypatch.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 41a72eb15..04b964b17 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -58,12 +58,13 @@ int LoadFileContents(const char* filename, FileContents* file) { return LoadPartitionContents(filename, file); } - if (stat(filename, &file->st) == -1) { + struct stat sb; + if (stat(filename, &sb) == -1) { printf("failed to stat \"%s\": %s\n", filename, strerror(errno)); return -1; } - std::vector data(file->st.st_size); + std::vector data(sb.st_size); unique_file f(ota_fopen(filename, "rb")); if (!f) { printf("failed to open \"%s\": %s\n", filename, strerror(errno)); @@ -180,10 +181,6 @@ static int LoadPartitionContents(const std::string& filename, FileContents* file buffer.resize(buffer_size); file->data = std::move(buffer); - // Fake some stat() info. - file->st.st_mode = 0644; - file->st.st_uid = 0; - file->st.st_gid = 0; return 0; } @@ -212,15 +209,6 @@ int SaveFileContents(const char* filename, const FileContents* file) { return -1; } - if (chmod(filename, file->st.st_mode) != 0) { - printf("chmod of \"%s\" failed: %s\n", filename, strerror(errno)); - return -1; - } - if (chown(filename, file->st.st_uid, file->st.st_gid) != 0) { - printf("chown of \"%s\" failed: %s\n", filename, strerror(errno)); - return -1; - } - return 0; } -- cgit v1.2.3 From e40c80d021d667c1400b7a5d1f6d623b8450a47c Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Sat, 3 Feb 2018 17:20:56 -0800 Subject: Skip the cache size check on host When running the update simulation, we choose to skip the cache size check for now due to the lack of "/cache" on host. And in later cls we can implement a cache size estimator to make the check more constrained. Also build the host version of support libraries. Test: unit test pass Change-Id: I3ed93c857fd02f7b62f5baba9130f75c3236e717 --- applypatch/applypatch.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 04b964b17..73701abc9 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -450,9 +450,8 @@ int CacheSizeCheck(size_t bytes) { if (MakeFreeSpaceOnCache(bytes) < 0) { printf("unable to make %zu bytes available on /cache\n", bytes); return 1; - } else { - return 0; } + return 0; } // This function applies binary patches to EMMC target files in a way that is safe (the original @@ -477,7 +476,7 @@ int CacheSizeCheck(size_t bytes) { // become obsolete since we have dropped the support for patching non-EMMC targets (EMMC targets // have the size embedded in the filename). int applypatch(const char* source_filename, const char* target_filename, - const char* target_sha1_str, size_t target_size __unused, + const char* target_sha1_str, size_t /* target_size */, const std::vector& patch_sha1_str, const std::vector>& patch_data, const Value* bonus_data) { printf("patch %s: ", source_filename); -- cgit v1.2.3 From 3bbb20f557790c015e44098098375eb6cc376a42 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Tue, 27 Feb 2018 15:56:11 -0800 Subject: Add a singleton CacheLocation to replace the hard coded locations This class allows us to set the following locations dynamically: cache_temp_source, last_command_file, stash_directory_base. In the updater's main function, we reset the values of these variables to their default locations in /cache; while we can set them to temp files in unit tests or host simulation. Test: unit tests pass Change-Id: I528652650caa41373617ab055d41b1f1a4ec0f87 --- applypatch/applypatch.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'applypatch/applypatch.cpp') diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 73701abc9..7645a4005 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -40,10 +40,9 @@ #include "edify/expr.h" #include "otafault/ota_io.h" +#include "otautil/cache_location.h" #include "otautil/print_sha1.h" -std::string cache_temp_source = "/cache/saved.file"; - static int LoadPartitionContents(const std::string& filename, FileContents* file); static size_t FileSink(const unsigned char* data, size_t len, int fd); static int GenerateTarget(const FileContents& source_file, const std::unique_ptr& patch, @@ -404,7 +403,7 @@ int applypatch_check(const char* filename, const std::vector& patch // If the source file is missing or corrupted, it might be because we were killed in the middle // of patching it. A copy of it should have been made in cache_temp_source. If that file // exists and matches the sha1 we're looking for, the check still passes. - if (LoadFileContents(cache_temp_source.c_str(), &file) != 0) { + if (LoadFileContents(CacheLocation::location().cache_temp_source().c_str(), &file) != 0) { printf("failed to load cache file\n"); return 1; } @@ -526,7 +525,7 @@ int applypatch(const char* source_filename, const char* target_filename, printf("source file is bad; trying copy\n"); FileContents copy_file; - if (LoadFileContents(cache_temp_source.c_str(), ©_file) < 0) { + if (LoadFileContents(CacheLocation::location().cache_temp_source().c_str(), ©_file) < 0) { printf("failed to read copy file\n"); return 1; } @@ -621,7 +620,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr printf("not enough free space on /cache\n"); return 1; } - if (SaveFileContents(cache_temp_source.c_str(), &source_file) < 0) { + if (SaveFileContents(CacheLocation::location().cache_temp_source().c_str(), &source_file) < 0) { printf("failed to back up source file\n"); return 1; } @@ -667,7 +666,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr } // Delete the backup copy of the source. - unlink(cache_temp_source.c_str()); + unlink(CacheLocation::location().cache_temp_source().c_str()); // Success! return 0; -- cgit v1.2.3