From 347b2dac978839a1bb38d13649fee8a02d0628b5 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 17 Jul 2024 19:10:17 +0900 Subject: [PATCH] fota: Modify upgrade checking function more readable Previously, the function is_upgrade_completed() gets no argument and returns -1 if error, 0 if upgrade is not completed, 1 if upgrade is completed. This might confusing since the return value does two role: indicating error and upgrade completion. To increase the readability, the return value is only shows if function call is succeed or not and upgrade completion is returned using bool type parameter "upgrade_completed". Also, the behavior of function is changed to 'get boolean value about upgrade is done or not', so the name of this function is changed to get_upgrade_completed. Change-Id: I377db07b10d42f253ca44a973b25bbf06583a27c Signed-off-by: SangYoun Kwak --- update-manager/fota/fota-installer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/update-manager/fota/fota-installer.c b/update-manager/fota/fota-installer.c index 99d6454..b59693b 100644 --- a/update-manager/fota/fota-installer.c +++ b/update-manager/fota/fota-installer.c @@ -462,7 +462,7 @@ int fota_installer_finish_update(void) return exec_status > 0 ? -exec_status : exec_status; } -static int is_upgrade_completed(void) +static int get_upgrade_completed(bool *upgrade_completed) { char boot_mode[128]; int upgrde_progress_status = 0; @@ -483,15 +483,19 @@ static int is_upgrade_completed(void) if (upgrde_progress_status != 100) { _FLOGI("Upgrade not completed: upgrade progress status is not 100 but %d", upgrde_progress_status); + *upgrade_completed = false; return 0; } if (strncmp(boot_mode, "normal", sizeof(boot_mode)) != 0) { _FLOGI("Boot mode is not normal: %s", boot_mode); + *upgrade_completed = false; return 0; } - return 1; + *upgrade_completed = true; + + return 0; } int fota_installer_check_and_set_upgrade_state_completed(void) @@ -499,14 +503,15 @@ int fota_installer_check_and_set_upgrade_state_completed(void) char current_upgrade_state[128]; char *next_upgrade_state = "completed"; int ret = 0; + bool upgrade_completed = false; - ret = is_upgrade_completed(); - if (ret < 0) { + ret = get_upgrade_completed(&upgrade_completed); + if (ret != 0) { _FLOGE("Failed to check if upgrade completed."); return -1; } - if (ret == 0) { + if (!upgrade_completed) { _FLOGI("Upgrade is not completed."); return 0; } -- 2.34.1