From 93015f366b0036c33923800821fae02d4f068e3c Mon Sep 17 00:00:00 2001 From: chenzihan Date: Sun, 24 Apr 2022 14:14:50 +0800 Subject: [PATCH 1/2] Signed-off-by: chenzihan fix:diff from minelibary_release --- interfaces/kits/include/misc_info/misc_info.h | 2 ++ interfaces/kits/misc_info/misc_info.cpp | 17 +++++++++ services/fs_manager/mount.cpp | 12 +++++-- services/include/updater/updater_const.h | 3 ++ services/updater_main.cpp | 3 +- services/updater_utils.cpp | 16 +++++---- utils/include/utils.h | 1 + utils/utils.cpp | 35 +++++++++++++++++++ 8 files changed, 79 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/include/misc_info/misc_info.h b/interfaces/kits/include/misc_info/misc_info.h index 38f781fd..a69cc8e2 100755 --- a/interfaces/kits/include/misc_info/misc_info.h +++ b/interfaces/kits/include/misc_info/misc_info.h @@ -47,5 +47,7 @@ struct UpdateMessage { bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot); bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot); +bool WriteUpdaterMiscMsg(const UpdateMessage &boot); +bool ReadUpdaterMiscMsg(UpdateMessage &boot); } // updater #endif /* MISC_INFO_H */ diff --git a/interfaces/kits/misc_info/misc_info.cpp b/interfaces/kits/misc_info/misc_info.cpp index cf40c7f4..70b55bef 100755 --- a/interfaces/kits/misc_info/misc_info.cpp +++ b/interfaces/kits/misc_info/misc_info.cpp @@ -19,6 +19,7 @@ #include "fs_manager/mount.h" #include "log/log.h" #include "securec.h" +#include "updater_const.h" namespace updater { bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot) @@ -55,4 +56,20 @@ bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot) "ReadUpdaterMessage memcpy failed", return false); return true; } + +bool WriteUpdaterMiscMsg(const UpdateMessage &boot) +{ + auto path = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", path = MISC_FILE); + LOG(INFO) << "WriteUpdaterMiscMsg::misc path : " << path; + return WriteUpdaterMessage(path, boot); +} + +bool ReadUpdaterMiscMsg(UpdateMessage &boot) +{ + auto path = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", path = MISC_FILE); + LOG(INFO) << "ReadUpdaterMiscMsg::misc path : " << path; + return ReadUpdaterMessage(path, boot); +} } // updater diff --git a/services/fs_manager/mount.cpp b/services/fs_manager/mount.cpp index 0a71611f..a2424bf0 100644 --- a/services/fs_manager/mount.cpp +++ b/services/fs_manager/mount.cpp @@ -28,7 +28,9 @@ namespace updater { using updater::utils::SplitString; static std::string g_defaultUpdaterFstab = ""; -static Fstab *g_fstab; +static Fstab *g_fstab = nullptr; +static const std::string PARTITION_PATH = "/dev/block/by-name"; + static std::string GetFstabFile() { /* check vendor fstab files from specific directory */ @@ -187,8 +189,12 @@ int SetupPartitions() const std::string GetBlockDeviceByMountPoint(const std::string &mountPoint) { - std::string blockDevice = ""; - if (!mountPoint.empty()) { + if (mountPoint.empty()) { + LOG(ERROR) << "mountPoint empty error."; + return ""; + } + std::string blockDevice = PARTITION_PATH + mountPoint; + if (g_fstab != nullptr) { FstabItem *item = FindFstabItemForMountPoint(*g_fstab, mountPoint.c_str()); if (item != NULL) { blockDevice = item->deviceName; diff --git a/services/include/updater/updater_const.h b/services/include/updater/updater_const.h index 6b447687..f1f21cee 100644 --- a/services/include/updater/updater_const.h +++ b/services/include/updater/updater_const.h @@ -24,7 +24,10 @@ const std::string TMP_STAGE_LOG = "/tmp/updater_stage.log"; const std::string TMP_ERROR_CODE_PATH = "/tmp/error_code.log"; const std::string UPDATER_LOG_DIR = "/data/updater/log"; const std::string UPDATER_PATH = "/data/updater"; +const std::string DATA_PATH = "/data"; +const std::string UPDATER_RESULT_FILE = "updater_result"; const std::string MISC_FILE = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc"; +const std::string MISC_PATH = "/misc"; const std::string UPDATER_BINARY = "updater_binary"; const std::string SDCARD_PATH = "/sdcard"; const std::string UPDATER_HDC_LOG = "/data/updater/log/flashd_hdc.log"; diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 9b393a6d..a71dab05 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -77,7 +77,7 @@ static void SetRetryCountToMisc(int retryCount, const std::vector a "SetRetryCountToMisc snprintf_s failed", return); UPDATER_ERROR_CHECK(!strncat_s(msg.update, sizeof(msg.update), buffer, strlen(buffer) + 1), "SetRetryCountToMisc strncat_s failed", return); - UPDATER_ERROR_CHECK_NOT_RETURN(WriteUpdaterMessage(MISC_FILE, msg) == true, "Write command to misc failed."); + UPDATER_ERROR_CHECK_NOT_RETURN(WriteUpdaterMiscMsg(msg) == true, "Write command to misc failed."); } static int DoFactoryReset(FactoryResetMode mode, const std::string &path) @@ -194,6 +194,7 @@ static UpdaterStatus StartUpdaterEntry(PkgManager::PkgManagerPtr manager, if (upParams.updatePackage != "") { ShowUpdateFrame(true); status = InstallUpdaterPackage(upParams, args, manager); + WriteOtaResult(status); UPDATER_CHECK_ONLY_RETURN(status == UPDATE_SUCCESS, return status); } else if (upParams.factoryWipeData) { LOG(INFO) << "Factory level FactoryReset begin"; diff --git a/services/updater_utils.cpp b/services/updater_utils.cpp index dc928c74..a9c77238 100755 --- a/services/updater_utils.cpp +++ b/services/updater_utils.cpp @@ -129,7 +129,8 @@ static bool DeleteUpdaterPath(const std::string &path) struct dirent *dp = nullptr; while ((dp = readdir(pDir.get())) != nullptr) { std::string currentName(dp->d_name); - if (currentName[0] != '.' && (currentName.compare("log") != 0)) { + if (currentName[0] != '.' && (currentName.compare("log") != 0) && + (currentName.compare(UPDATER_RESULT_FILE) != 0)) { std::string tmpName(path); tmpName.append("/" + currentName); if (IsDir(tmpName)) { @@ -146,9 +147,12 @@ static bool DeleteUpdaterPath(const std::string &path) static bool ClearMisc() { struct UpdateMessage cleanBoot {}; - UPDATER_ERROR_CHECK(WriteUpdaterMessage(MISC_FILE, cleanBoot) == true, + UPDATER_ERROR_CHECK(WriteUpdaterMiscMsg(cleanBoot) == true, "ClearMisc clear boot message to misc failed", return false); - auto fp = std::unique_ptr(fopen(MISC_FILE.c_str(), "rb+"), fclose); + auto miscBlockDev = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", miscBlockDev = MISC_FILE); + LOG(INFO) << "ClearMisc::misc path : " << miscBlockDev; + auto fp = std::unique_ptr(fopen(miscBlockDev.c_str(), "rb+"), fclose); UPDATER_FILE_CHECK(fp != nullptr, "WriteVersionCode fopen failed", return false); (void)fseek(fp.get(), PARTITION_RECORD_OFFSET, SEEK_SET); off_t clearOffset = 0; @@ -260,7 +264,7 @@ int IsSpaceCapacitySufficient(const std::string &packagePath) UPDATER_ERROR_CHECK(ret >= 0, "Statvfs read /sdcard error!", return UPDATE_ERROR); } else { needSpace += MAX_LOG_SPACE; - ret = statvfs64(UPDATER_PATH.c_str(), &updaterVfs); + ret = statvfs64(DATA_PATH.c_str(), &updaterVfs); UPDATER_ERROR_CHECK(ret >= 0, "Statvfs read /data error!", return UPDATE_ERROR); } auto freeSpaceSize = static_cast(updaterVfs.f_bfree); @@ -275,7 +279,7 @@ std::vector ParseParams(int argc, char **argv) { struct UpdateMessage boot {}; // read from misc - UPDATER_ERROR_CHECK_NOT_RETURN(ReadUpdaterMessage(MISC_FILE, boot) == true, + UPDATER_ERROR_CHECK_NOT_RETURN(ReadUpdaterMiscMsg(MISC_FILE, boot) == true, "ReadUpdaterMessage MISC_FILE failed!"); // if boot.update is empty, read from command.The Misc partition may have dirty data, // so strlen(boot.update) is not used, which can cause system exceptions. @@ -300,7 +304,7 @@ int GetBootMode(int &mode) #endif struct UpdateMessage boot {}; // read from misc - bool ret = ReadUpdaterMessage(MISC_FILE, boot); + bool ret = ReadUpdaterMiscMsg(MISC_FILE, boot); if (!ret) { return -1; } diff --git a/utils/include/utils.h b/utils/include/utils.h index 62366084..f1b6f928 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -55,6 +55,7 @@ bool ReadFully(int fd, void* data, size_t size); bool ReadFileToString(int fd, std::string &content); bool WriteStringToFile(int fd, const std::string& content); std::string GetLocalBoardId(); +void WriteOtaResult(const int status); } // utils } // updater #endif // UPDATER_UTILS_H diff --git a/utils/utils.cpp b/utils/utils.cpp index 3da6a9a1..afcff36e 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -39,6 +39,9 @@ using namespace hpackage; namespace utils { constexpr uint32_t MAX_PATH_LEN = 256; constexpr uint8_t SHIFT_RIGHT_FOUR_BITS = 4; +constexpr int USER_ROOT_AUTHORITY = 0; +constexpr int GROUP_SYS_AUTHORITY = 1000; +constexpr int MAX_RESULT_SIZE = 20; int32_t DeleteFile(const std::string& filename) { UPDATER_ERROR_CHECK (!filename.empty(), "Invalid filename", return -1); @@ -287,5 +290,37 @@ std::string GetLocalBoardId() { return "HI3516"; } + +void WriteOtaResult(const int status) +{ + if (access(UPDATER_PATH.c_str(), 0) != 0) { + UPDATER_ERROR_CHECK(!MkdirRecursive(UPDATER_PATH, 0644), + "MkdirRecursive error!", return); + } + + const std::sting resultPath = UPDATER_PATH + "/" + UPDATER_RESULT_FILE; + FILE *fp = fopen(resultPath.c_str(), "w+"); + if (fp != nullptr) { + LOG(ERROR) << "open result file fialed"; + return; + } + char buff[MAX_RESULT_SIZE] = "pass\n"; + if (status != 0) { + if (sprintf_s(buf, MAX_RESULT_SIZE - 1, "fail:%d\n", status) < 0) { + LOG(WARNING) << "sprintf status failed"; + } + } + + if (fwrite(buf, 1, strlen(buf) + 1, fp) <= 0) { + LOG(WARNING) << "write result file failed, err:" << errno; + } + + if (fclose(fp) != 0) { + LOG(WARNING) << "close result file failed"; + } + + (void)chown(resultPath.c_str(), USER_ROOT_AUTHORITY, GROUP_SYS_AUTHORITY); + (void)chown(resultPath.c_str(), 0640); // 0640: -rw-r----- +} } // utils } // namespace updater -- Gitee From e801c889ec47632e9971a7e5bdf30a474e8d790e Mon Sep 17 00:00:00 2001 From: chenzihan Date: Sun, 24 Apr 2022 14:14:50 +0800 Subject: [PATCH 2/2] Signed-off-by: chenzihan fix:diff from minelibary_release --- interfaces/kits/include/misc_info/misc_info.h | 2 ++ interfaces/kits/misc_info/misc_info.cpp | 17 +++++++++ services/fs_manager/mount.cpp | 12 +++++-- services/include/updater/updater_const.h | 3 ++ services/ui/input_event.cpp | 2 +- services/ui/updater_ui_const.h | 4 +-- services/updater_main.cpp | 3 +- services/updater_utils.cpp | 16 +++++---- utils/include/utils.h | 1 + utils/utils.cpp | 35 +++++++++++++++++++ 10 files changed, 82 insertions(+), 13 deletions(-) diff --git a/interfaces/kits/include/misc_info/misc_info.h b/interfaces/kits/include/misc_info/misc_info.h index 38f781fd..a69cc8e2 100755 --- a/interfaces/kits/include/misc_info/misc_info.h +++ b/interfaces/kits/include/misc_info/misc_info.h @@ -47,5 +47,7 @@ struct UpdateMessage { bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot); bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot); +bool WriteUpdaterMiscMsg(const UpdateMessage &boot); +bool ReadUpdaterMiscMsg(UpdateMessage &boot); } // updater #endif /* MISC_INFO_H */ diff --git a/interfaces/kits/misc_info/misc_info.cpp b/interfaces/kits/misc_info/misc_info.cpp index cf40c7f4..70b55bef 100755 --- a/interfaces/kits/misc_info/misc_info.cpp +++ b/interfaces/kits/misc_info/misc_info.cpp @@ -19,6 +19,7 @@ #include "fs_manager/mount.h" #include "log/log.h" #include "securec.h" +#include "updater_const.h" namespace updater { bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot) @@ -55,4 +56,20 @@ bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot) "ReadUpdaterMessage memcpy failed", return false); return true; } + +bool WriteUpdaterMiscMsg(const UpdateMessage &boot) +{ + auto path = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", path = MISC_FILE); + LOG(INFO) << "WriteUpdaterMiscMsg::misc path : " << path; + return WriteUpdaterMessage(path, boot); +} + +bool ReadUpdaterMiscMsg(UpdateMessage &boot) +{ + auto path = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", path = MISC_FILE); + LOG(INFO) << "ReadUpdaterMiscMsg::misc path : " << path; + return ReadUpdaterMessage(path, boot); +} } // updater diff --git a/services/fs_manager/mount.cpp b/services/fs_manager/mount.cpp index 0a71611f..a2424bf0 100644 --- a/services/fs_manager/mount.cpp +++ b/services/fs_manager/mount.cpp @@ -28,7 +28,9 @@ namespace updater { using updater::utils::SplitString; static std::string g_defaultUpdaterFstab = ""; -static Fstab *g_fstab; +static Fstab *g_fstab = nullptr; +static const std::string PARTITION_PATH = "/dev/block/by-name"; + static std::string GetFstabFile() { /* check vendor fstab files from specific directory */ @@ -187,8 +189,12 @@ int SetupPartitions() const std::string GetBlockDeviceByMountPoint(const std::string &mountPoint) { - std::string blockDevice = ""; - if (!mountPoint.empty()) { + if (mountPoint.empty()) { + LOG(ERROR) << "mountPoint empty error."; + return ""; + } + std::string blockDevice = PARTITION_PATH + mountPoint; + if (g_fstab != nullptr) { FstabItem *item = FindFstabItemForMountPoint(*g_fstab, mountPoint.c_str()); if (item != NULL) { blockDevice = item->deviceName; diff --git a/services/include/updater/updater_const.h b/services/include/updater/updater_const.h index 6b447687..f1f21cee 100644 --- a/services/include/updater/updater_const.h +++ b/services/include/updater/updater_const.h @@ -24,7 +24,10 @@ const std::string TMP_STAGE_LOG = "/tmp/updater_stage.log"; const std::string TMP_ERROR_CODE_PATH = "/tmp/error_code.log"; const std::string UPDATER_LOG_DIR = "/data/updater/log"; const std::string UPDATER_PATH = "/data/updater"; +const std::string DATA_PATH = "/data"; +const std::string UPDATER_RESULT_FILE = "updater_result"; const std::string MISC_FILE = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc"; +const std::string MISC_PATH = "/misc"; const std::string UPDATER_BINARY = "updater_binary"; const std::string SDCARD_PATH = "/sdcard"; const std::string UPDATER_HDC_LOG = "/data/updater/log/flashd_hdc.log"; diff --git a/services/ui/input_event.cpp b/services/ui/input_event.cpp index 5867bb6e..2c97f106 100644 --- a/services/ui/input_event.cpp +++ b/services/ui/input_event.cpp @@ -22,7 +22,7 @@ namespace updater { constexpr int TOUCH_LOW_TH = 50; constexpr int TOUCH_HIGH_TH = 90; constexpr int INIT_DEFAULT_VALUE = 255; -constexpr int LABEL_HEIGHT = 64; +constexpr int LABEL_HEIGHT = 80; constexpr int LABEL_OFFSET_2 = 2; constexpr int LABEL_OFFSET_3 = 3; constexpr int DIALOG_START_Y = 550; diff --git a/services/ui/updater_ui_const.h b/services/ui/updater_ui_const.h index 99381a70..5dd2d03b 100644 --- a/services/ui/updater_ui_const.h +++ b/services/ui/updater_ui_const.h @@ -53,8 +53,8 @@ constexpr int DIALOG_OK_ID = 200; constexpr int DIALOG_CANCEL_ID = 201; constexpr int DIALOG_CANCEL_X = 340; constexpr int DIALOG_OK_WIDTH = 150; -constexpr int SCREEN_WIDTH = 480; -constexpr int SCREEN_HEIGHT = 960; +constexpr int SCREEN_WIDTH = 720; +constexpr int SCREEN_HEIGHT = 1280; constexpr int MEDIAN_NUMBER = 2; } // namespace updater #endif /* UPDATE_UI_HOS_UPDATER_H */ \ No newline at end of file diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 9b393a6d..a71dab05 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -77,7 +77,7 @@ static void SetRetryCountToMisc(int retryCount, const std::vector a "SetRetryCountToMisc snprintf_s failed", return); UPDATER_ERROR_CHECK(!strncat_s(msg.update, sizeof(msg.update), buffer, strlen(buffer) + 1), "SetRetryCountToMisc strncat_s failed", return); - UPDATER_ERROR_CHECK_NOT_RETURN(WriteUpdaterMessage(MISC_FILE, msg) == true, "Write command to misc failed."); + UPDATER_ERROR_CHECK_NOT_RETURN(WriteUpdaterMiscMsg(msg) == true, "Write command to misc failed."); } static int DoFactoryReset(FactoryResetMode mode, const std::string &path) @@ -194,6 +194,7 @@ static UpdaterStatus StartUpdaterEntry(PkgManager::PkgManagerPtr manager, if (upParams.updatePackage != "") { ShowUpdateFrame(true); status = InstallUpdaterPackage(upParams, args, manager); + WriteOtaResult(status); UPDATER_CHECK_ONLY_RETURN(status == UPDATE_SUCCESS, return status); } else if (upParams.factoryWipeData) { LOG(INFO) << "Factory level FactoryReset begin"; diff --git a/services/updater_utils.cpp b/services/updater_utils.cpp index dc928c74..a9c77238 100755 --- a/services/updater_utils.cpp +++ b/services/updater_utils.cpp @@ -129,7 +129,8 @@ static bool DeleteUpdaterPath(const std::string &path) struct dirent *dp = nullptr; while ((dp = readdir(pDir.get())) != nullptr) { std::string currentName(dp->d_name); - if (currentName[0] != '.' && (currentName.compare("log") != 0)) { + if (currentName[0] != '.' && (currentName.compare("log") != 0) && + (currentName.compare(UPDATER_RESULT_FILE) != 0)) { std::string tmpName(path); tmpName.append("/" + currentName); if (IsDir(tmpName)) { @@ -146,9 +147,12 @@ static bool DeleteUpdaterPath(const std::string &path) static bool ClearMisc() { struct UpdateMessage cleanBoot {}; - UPDATER_ERROR_CHECK(WriteUpdaterMessage(MISC_FILE, cleanBoot) == true, + UPDATER_ERROR_CHECK(WriteUpdaterMiscMsg(cleanBoot) == true, "ClearMisc clear boot message to misc failed", return false); - auto fp = std::unique_ptr(fopen(MISC_FILE.c_str(), "rb+"), fclose); + auto miscBlockDev = GetBlockDeviceByMountPoint(MISC_PATH); + UPDATER_INFO_CHECK(!path.empty(), "cannot get block device of partition", miscBlockDev = MISC_FILE); + LOG(INFO) << "ClearMisc::misc path : " << miscBlockDev; + auto fp = std::unique_ptr(fopen(miscBlockDev.c_str(), "rb+"), fclose); UPDATER_FILE_CHECK(fp != nullptr, "WriteVersionCode fopen failed", return false); (void)fseek(fp.get(), PARTITION_RECORD_OFFSET, SEEK_SET); off_t clearOffset = 0; @@ -260,7 +264,7 @@ int IsSpaceCapacitySufficient(const std::string &packagePath) UPDATER_ERROR_CHECK(ret >= 0, "Statvfs read /sdcard error!", return UPDATE_ERROR); } else { needSpace += MAX_LOG_SPACE; - ret = statvfs64(UPDATER_PATH.c_str(), &updaterVfs); + ret = statvfs64(DATA_PATH.c_str(), &updaterVfs); UPDATER_ERROR_CHECK(ret >= 0, "Statvfs read /data error!", return UPDATE_ERROR); } auto freeSpaceSize = static_cast(updaterVfs.f_bfree); @@ -275,7 +279,7 @@ std::vector ParseParams(int argc, char **argv) { struct UpdateMessage boot {}; // read from misc - UPDATER_ERROR_CHECK_NOT_RETURN(ReadUpdaterMessage(MISC_FILE, boot) == true, + UPDATER_ERROR_CHECK_NOT_RETURN(ReadUpdaterMiscMsg(MISC_FILE, boot) == true, "ReadUpdaterMessage MISC_FILE failed!"); // if boot.update is empty, read from command.The Misc partition may have dirty data, // so strlen(boot.update) is not used, which can cause system exceptions. @@ -300,7 +304,7 @@ int GetBootMode(int &mode) #endif struct UpdateMessage boot {}; // read from misc - bool ret = ReadUpdaterMessage(MISC_FILE, boot); + bool ret = ReadUpdaterMiscMsg(MISC_FILE, boot); if (!ret) { return -1; } diff --git a/utils/include/utils.h b/utils/include/utils.h index 62366084..f1b6f928 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -55,6 +55,7 @@ bool ReadFully(int fd, void* data, size_t size); bool ReadFileToString(int fd, std::string &content); bool WriteStringToFile(int fd, const std::string& content); std::string GetLocalBoardId(); +void WriteOtaResult(const int status); } // utils } // updater #endif // UPDATER_UTILS_H diff --git a/utils/utils.cpp b/utils/utils.cpp index 3da6a9a1..afcff36e 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -39,6 +39,9 @@ using namespace hpackage; namespace utils { constexpr uint32_t MAX_PATH_LEN = 256; constexpr uint8_t SHIFT_RIGHT_FOUR_BITS = 4; +constexpr int USER_ROOT_AUTHORITY = 0; +constexpr int GROUP_SYS_AUTHORITY = 1000; +constexpr int MAX_RESULT_SIZE = 20; int32_t DeleteFile(const std::string& filename) { UPDATER_ERROR_CHECK (!filename.empty(), "Invalid filename", return -1); @@ -287,5 +290,37 @@ std::string GetLocalBoardId() { return "HI3516"; } + +void WriteOtaResult(const int status) +{ + if (access(UPDATER_PATH.c_str(), 0) != 0) { + UPDATER_ERROR_CHECK(!MkdirRecursive(UPDATER_PATH, 0644), + "MkdirRecursive error!", return); + } + + const std::sting resultPath = UPDATER_PATH + "/" + UPDATER_RESULT_FILE; + FILE *fp = fopen(resultPath.c_str(), "w+"); + if (fp != nullptr) { + LOG(ERROR) << "open result file fialed"; + return; + } + char buff[MAX_RESULT_SIZE] = "pass\n"; + if (status != 0) { + if (sprintf_s(buf, MAX_RESULT_SIZE - 1, "fail:%d\n", status) < 0) { + LOG(WARNING) << "sprintf status failed"; + } + } + + if (fwrite(buf, 1, strlen(buf) + 1, fp) <= 0) { + LOG(WARNING) << "write result file failed, err:" << errno; + } + + if (fclose(fp) != 0) { + LOG(WARNING) << "close result file failed"; + } + + (void)chown(resultPath.c_str(), USER_ROOT_AUTHORITY, GROUP_SYS_AUTHORITY); + (void)chown(resultPath.c_str(), 0640); // 0640: -rw-r----- +} } // utils } // namespace updater -- Gitee