diff --git a/services/applypatch/block_set.cpp b/services/applypatch/block_set.cpp index 0b0cddee5c275e8b13288e2315581aafca0b3012..13d107fd748967e70c0fd0ba589bb2f72a83a97c 100644 --- a/services/applypatch/block_set.cpp +++ b/services/applypatch/block_set.cpp @@ -356,7 +356,7 @@ int32_t BlockSet::WriteZeroToBlock(int fd, bool isErase) off64_t offset = static_cast(iter->first * H_BLOCK_SIZE); int ret = 0; - if (isErase) { + if (isErase && Utils::IsUpdaterMode()) { #ifndef UPDATER_UT size_t writeSize = (iter->second - iter->first) * H_BLOCK_SIZE; uint64_t arguments[2] = {static_cast(offset), writeSize}; diff --git a/services/applypatch/command_process.cpp b/services/applypatch/command_process.cpp index 39569b3b0045b68cf3250fbd2cc671503473ee99..ab5e82ff85a0e7f24cd0140e8c183afcd713cab2 100644 --- a/services/applypatch/command_process.cpp +++ b/services/applypatch/command_process.cpp @@ -120,7 +120,7 @@ CommandResult ZeroAndEraseCommandFn::Execute(const Command ¶ms) isErase = true; LOG(INFO) << "Start run ERASE command"; } - if (isErase) { + if (isErase && Utils::IsUpdaterMode()) { struct stat statBlock {}; if (fstat(params.GetTargetFileDescriptor(), &statBlock) == -1) { LOG(ERROR) << "Failed to fstat"; diff --git a/services/updater_binary/BUILD.gn b/services/updater_binary/BUILD.gn index 3f79682c84790f2295e8ab5454f75049032eb3f0..e196cd239de036fca9d1ea4efc93d35232cfdfd5 100644 --- a/services/updater_binary/BUILD.gn +++ b/services/updater_binary/BUILD.gn @@ -52,7 +52,7 @@ ohos_static_library("libupdater_binary") { "${updater_path}/services/updater_binary/update_processor.cpp", "${updater_path}/services/updater_binary/update_processor_stream.cpp", ] - configs = [ ":updater_config" ] + public_configs = [ ":updater_config" ] ldflags = [ "-Wl -std=c++11" ] diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index c0953a4e154aa3270e8c1269d2bb58fdd420246c..9e1c49fcf6ed996500c8f5c61e1d18b25e5fa318 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -42,6 +42,15 @@ constexpr int32_t SHA_CHECK_PARAMS = 3; constexpr int32_t SHA_CHECK_TARGETPAIRS_INDEX = 3; constexpr int32_t SHA_CHECK_TARGETSHA_INDEX = 4; constexpr int32_t SHA_CHECK_TARGET_PARAMS = 5; + +__attribute__((weak)) void GetWriteDevPath(const std::string &path, [[maybe_unused]]const std::string &partitionName, + std::string &devPath) +{ + devPath = path; + LOG(INFO) << "GetWriteDevPath: " << devPath; + return; +} + static int ExtractNewData(const PkgBuffer &buffer, size_t size, size_t start, bool isFinish, const void* context) { void *p = const_cast(context); @@ -134,14 +143,6 @@ static int32_t ReturnAndPushParam(int32_t returnValue, Uscript::UScriptContext & return returnValue; } -struct UpdateBlockInfo { - std::string partitionName; - std::string transferName; - std::string newDataName; - std::string patchDataName; - std::string devPath; -}; - static int32_t GetUpdateBlockInfo(struct UpdateBlockInfo &infos, Uscript::UScriptEnv &env, Uscript::UScriptContext &context) { @@ -293,7 +294,9 @@ static int32_t ExtractDiffPackageAndLoad(const UpdateBlockInfo &infos, Uscript:: static int32_t DoExecuteUpdateBlock(const UpdateBlockInfo &infos, TransferManagerPtr tm, Hpackage::PkgManager::StreamPtr &outStream, const std::vector &lines, Uscript::UScriptContext &context) { - int fd = open(infos.devPath.c_str(), O_RDWR | O_LARGEFILE); + std::string devPath = ""; + GetWriteDevPath(infos.devPath, infos.partitionName, devPath); + int fd = open(devPath.c_str(), O_RDWR | O_LARGEFILE); auto env = tm->GetTransferParams()->env; if (fd == -1) { LOG(ERROR) << "Failed to open block"; diff --git a/services/updater_binary/update_image_block.h b/services/updater_binary/update_image_block.h index 2d9f58b20986d0fb28f141176b41e3a05463ba5c..a8c192f830d15d7bf834f3b685530fcea7dc5e1e 100644 --- a/services/updater_binary/update_image_block.h +++ b/services/updater_binary/update_image_block.h @@ -20,6 +20,14 @@ #include "script_manager.h" namespace Updater { +struct UpdateBlockInfo { + std::string partitionName; + std::string transferName; + std::string newDataName; + std::string patchDataName; + std::string devPath; +}; + class UScriptInstructionBlockUpdate : public Uscript::UScriptInstruction { public: UScriptInstructionBlockUpdate() {} @@ -57,6 +65,19 @@ private: int32_t SetShaInfo(Uscript::UScriptContext &context, ShaInfo &shaInfo); bool IsTargetShaDiff(const std::string &devPath, const ShaInfo &shaInfo); }; + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ +void GetWriteDevPath(const std::string &path, [[maybe_unused]]const std::string &partitionName, + std::string &devPath); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ } #endif // UPDATER_UPDATE_IMAGE_BLOCK_H