diff options
-rw-r--r-- | CleanSpec.mk | 3 | ||||
-rw-r--r-- | applypatch/Android.bp | 6 | ||||
-rw-r--r-- | applypatch/applypatch.cpp | 16 | ||||
-rw-r--r-- | applypatch/applypatch_modes.cpp | 2 | ||||
-rw-r--r-- | applypatch/include/applypatch/applypatch.h | 7 | ||||
-rw-r--r-- | recovery_main.cpp | 7 | ||||
-rw-r--r-- | tests/Android.bp | 1 | ||||
-rw-r--r-- | tests/unit/applypatch_test.cpp | 4 | ||||
-rw-r--r-- | updater/install.cpp | 2 |
9 files changed, 32 insertions, 16 deletions
diff --git a/CleanSpec.mk b/CleanSpec.mk index 8405d20e1..0980a35f3 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -58,6 +58,9 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/testcases/recovery_component_test) $(call add-clean-step, find $(OUT_DIR) -type f -name "SystemUpdaterSample*" -print0 | xargs -0 rm -f) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/priv-app/SystemUpdaterSample) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib*/libbrotli.so) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib*/libbz.so) + # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # ************************************************ diff --git a/applypatch/Android.bp b/applypatch/Android.bp index ae7e9c5cc..55d185201 100644 --- a/applypatch/Android.bp +++ b/applypatch/Android.bp @@ -106,13 +106,15 @@ cc_binary { "libapplypatch", "libedify", "libotautil", + + // External dependencies. "libbspatch", + "libbrotli", + "libbz", ], shared_libs: [ "libbase", - "libbrotli", - "libbz", "libcrypto", "liblog", "libz", diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 90d8e8604..336860cb9 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -47,7 +47,7 @@ using namespace std::string_literals; static bool GenerateTarget(const Partition& target, const FileContents& source_file, - const Value& patch, const Value* bonus_data); + const Value& patch, const Value* bonus_data, bool backup_source); bool LoadFileContents(const std::string& filename, FileContents* file) { // No longer allow loading contents from eMMC partitions. @@ -266,7 +266,7 @@ int ShowLicenses() { } bool PatchPartition(const Partition& target, const Partition& source, const Value& patch, - const Value* bonus) { + const Value* bonus, bool backup_source) { LOG(INFO) << "Patching " << target.name; // We try to load and check against the target hash first. @@ -280,7 +280,7 @@ bool PatchPartition(const Partition& target, const Partition& source, const Valu FileContents source_file; if (ReadPartitionToBuffer(source, &source_file, true)) { - return GenerateTarget(target, source_file, patch, bonus); + return GenerateTarget(target, source_file, patch, bonus, backup_source); } LOG(ERROR) << "Failed to find any match"; @@ -326,7 +326,7 @@ bool FlashPartition(const Partition& partition, const std::string& source_filena } static bool GenerateTarget(const Partition& target, const FileContents& source_file, - const Value& patch, const Value* bonus_data) { + const Value& patch, const Value* bonus_data, bool backup_source) { uint8_t expected_sha1[SHA_DIGEST_LENGTH]; if (ParseSha1(target.hash, expected_sha1) != 0) { LOG(ERROR) << "Failed to parse target hash \"" << target.hash << "\""; @@ -351,11 +351,11 @@ static bool GenerateTarget(const Partition& target, const FileContents& source_f } // We write the original source to cache, in case the partition write is interrupted. - if (!CheckAndFreeSpaceOnCache(source_file.data.size())) { + if (backup_source && !CheckAndFreeSpaceOnCache(source_file.data.size())) { LOG(ERROR) << "Not enough free space on /cache"; return false; } - if (!SaveFileContents(Paths::Get().cache_temp_source(), &source_file)) { + if (backup_source && !SaveFileContents(Paths::Get().cache_temp_source(), &source_file)) { LOG(ERROR) << "Failed to back up source file"; return false; } @@ -415,7 +415,9 @@ static bool GenerateTarget(const Partition& target, const FileContents& source_f } // Delete the backup copy of the source. - unlink(Paths::Get().cache_temp_source().c_str()); + if (backup_source) { + unlink(Paths::Get().cache_temp_source().c_str()); + } // Success! return true; diff --git a/applypatch/applypatch_modes.cpp b/applypatch/applypatch_modes.cpp index b46659808..bb5eeae9d 100644 --- a/applypatch/applypatch_modes.cpp +++ b/applypatch/applypatch_modes.cpp @@ -87,7 +87,7 @@ static int PatchMode(const std::string& target_emmc, const std::string& source_e bonus = std::make_unique<Value>(Value::Type::BLOB, std::move(bonus_contents)); } - return PatchPartition(target, source, patch, bonus.get()) ? 0 : 1; + return PatchPartition(target, source, patch, bonus.get(), false) ? 0 : 1; } static void Usage() { diff --git a/applypatch/include/applypatch/applypatch.h b/applypatch/include/applypatch/applypatch.h index 6fc6f0fc9..799f4b2d7 100644 --- a/applypatch/include/applypatch/applypatch.h +++ b/applypatch/include/applypatch/applypatch.h @@ -73,10 +73,11 @@ std::ostream& operator<<(std::ostream& os, const Partition& partition); // the 'target' Partition. While patching, it will backup the data on the source partition to // /cache, so that the patching could be resumed on interruption even if both of the source and // target partitions refer to the same device. The function is idempotent if called multiple times. -// An optional arg 'bonus' can be provided, if the patch was generated with a bonus output. -// Returns the patching result. +// 'bonus' can be provided if the patch was generated with a bonus output, or nullptr. +// 'backup_source' indicates whether the source partition should be backed up prior to the update +// (e.g. when doing in-place update). Returns the patching result. bool PatchPartition(const Partition& target, const Partition& source, const Value& patch, - const Value* bonus); + const Value* bonus, bool backup_source); // Returns whether the contents of the eMMC target or the cached file match the embedded hash. // It will look for the backup on /cache if the given partition doesn't match the checksum. diff --git a/recovery_main.cpp b/recovery_main.cpp index 28197bf40..a04c1bbae 100644 --- a/recovery_main.cpp +++ b/recovery_main.cpp @@ -351,6 +351,12 @@ int main(int argc, char** argv) { std::string locale; std::string reason; + // The code here is only interested in the options that signal the intent to start fastbootd or + // recovery. Unrecognized options are likely meant for recovery, which will be processed later in + // start_recovery(). Suppress the warnings for such -- even if some flags were indeed invalid, the + // code in start_recovery() will capture and report them. + opterr = 0; + int arg; int option_index; while ((arg = getopt_long(args_to_parse.size() - 1, args_to_parse.data(), "", OPTIONS, @@ -374,6 +380,7 @@ int main(int argc, char** argv) { } } optind = 1; + opterr = 1; if (locale.empty()) { if (HasCache()) { diff --git a/tests/Android.bp b/tests/Android.bp index 232697d70..3335c0b83 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -99,6 +99,7 @@ librecovery_static_libs = [ cc_test { name: "recovery_unit_test", isolated: true, + require_root: true, defaults: [ "recovery_test_defaults", diff --git a/tests/unit/applypatch_test.cpp b/tests/unit/applypatch_test.cpp index 794f2c103..218a224f8 100644 --- a/tests/unit/applypatch_test.cpp +++ b/tests/unit/applypatch_test.cpp @@ -141,7 +141,7 @@ TEST_F(ApplyPatchTest, PatchPartition) { ASSERT_TRUE(LoadFileContents(from_testdata_base("bonus.file"), &bonus_fc)); Value bonus(Value::Type::BLOB, std::string(bonus_fc.data.cbegin(), bonus_fc.data.cend())); - ASSERT_TRUE(PatchPartition(target_partition, source_partition, patch, &bonus)); + ASSERT_TRUE(PatchPartition(target_partition, source_partition, patch, &bonus, false)); } // Tests patching an eMMC target without a separate bonus file (i.e. recovery-from-boot patch has @@ -151,7 +151,7 @@ TEST_F(ApplyPatchTest, PatchPartitionWithoutBonusFile) { ASSERT_TRUE(LoadFileContents(from_testdata_base("recovery-from-boot-with-bonus.p"), &patch_fc)); Value patch(Value::Type::BLOB, std::string(patch_fc.data.cbegin(), patch_fc.data.cend())); - ASSERT_TRUE(PatchPartition(target_partition, source_partition, patch, nullptr)); + ASSERT_TRUE(PatchPartition(target_partition, source_partition, patch, nullptr, false)); } class FreeCacheTest : public ::testing::Test { diff --git a/updater/install.cpp b/updater/install.cpp index be0ceb06c..b617f62c1 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -271,7 +271,7 @@ Value* PatchPartitionFn(const char* name, State* state, return StringValue(""); } - bool result = PatchPartition(target, source, *values[0], nullptr); + bool result = PatchPartition(target, source, *values[0], nullptr, true); return StringValue(result ? "t" : ""); } |