Drop build_string.txt comparisons used to verify delta-device comaptibility 79/284479/7
authorAntoni Adaszkiewicz <a.adaszkiewi@samsung.com>
Mon, 31 Oct 2022 15:13:29 +0000 (16:13 +0100)
committerAntoni Adaszkiewicz <a.adaszkiewi@samsung.com>
Mon, 28 Nov 2022 11:55:12 +0000 (12:55 +0100)
and use delta-verifier binary to perform said verification

Change-Id: Iffff84cbeae8373308ea59aee43eefb67cf16265

update-manager/fota/fota-info-checker.c [deleted file]
update-manager/fota/fota-installer.c
update-manager/fota/fota-manager.h
update-manager/fota/fota-storage-checker.c
update-manager/main.c

diff --git a/update-manager/fota/fota-info-checker.c b/update-manager/fota/fota-info-checker.c
deleted file mode 100644 (file)
index 8957c97..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "../common/common.h"
-#include "fota-manager.h"
-
-#define SYSTEM_INFO_BUILD_STRING "tizen.org/system/build.date"
-
-static char *build_string = NULL;
-
-char *fota_info_get_build_string()
-{
-       return build_string;
-}
-
-int fota_info_checker_init()
-{
-       int ret = 0;
-
-       _FLOGI("Start process to get fota information");
-       ret = system_info_get_platform_string(SYSTEM_INFO_BUILD_STRING, &build_string);
-       if (ret != SYSTEM_INFO_ERROR_NONE) {
-               _FLOGE("system_info_get_platform_string failed : %d", ret);
-               return -1;
-       }
-
-       _FLOGI("Success to get fota information, build_string : %s", build_string);
-       return 0;
-}
-
-int fota_info_checker_fini()
-{
-       if (build_string)
-               free(build_string);
-
-       return 0;
-}
index cb68ec22b74c74d69c03e3df959e56b40e4bf366..c94f38d1e366829532107e32b1c11bf25d7e4d9d 100644 (file)
@@ -78,7 +78,7 @@ int fota_installer_execute(pid_t sender_pid)
 {
        int ret = 0, status = 0, exec_status = 0;
        char buf[MAX_BUFFER_SIZE] = {0, };
-       char *appid = NULL, *old_build_string = NULL;
+       char *appid = NULL;
        gchar *client_delta_path = NULL;
        pid_t pid;
 
@@ -100,29 +100,19 @@ int fota_installer_execute(pid_t sender_pid)
        _FLOGI("Delta found: %s", client_delta_path);
 
        /* 3. Check client have appropriate delta  */
-       ret = util_file_untar(client_delta_path, FOTA_DELTA_BUILD_STRING_DIR, FOTA_DELTA_BUILD_STRING_FILENAME);
+       ret = util_file_untar(client_delta_path, FOTA_DELTA_UPDATE_INFO_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME);
        if (ret < 0) {
                status = -1;
                goto execute_destroy;
        }
-
-       ret = util_file_read_single_line(FOTA_DELTA_BUILD_STRING_PATH, buf);
+       snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH);
+       ret = system(buf);
        if (ret < 0) {
+               _FLOGE("Delta verification failed due to an error [return code: %d].", ret);
                status = -1;
                goto execute_destroy;
-       }
-
-       old_build_string = fota_info_get_build_string();
-       if(old_build_string == NULL) {
-               _FLOGE("Failed to get current image build string");
-               status = -1;
-               goto execute_destroy;
-       }
-
-       if (!g_str_has_prefix(buf, FOTA_DELTA_BUILD_STRING_FULL_DELTA_PREFIX) &&
-           !g_str_has_prefix(buf, old_build_string)) {
-               _FLOGI("The caller doesn't have appropriate delta(%s), delta build string(%s)",
-                               old_build_string, buf);
+       } else if (ret > 0) {
+               _FLOGI("The delta of the caller is not compatible with this device [return code: %d].", ret);
                status = -3;
                goto execute_destroy;
        }
@@ -206,8 +196,6 @@ int fota_installer_execute(pid_t sender_pid)
        }
 
 execute_destroy:
-       util_file_remove(FOTA_DELTA_BUILD_STRING_PATH);
-
        if (client_delta_path)
                free(client_delta_path);
 
index 72d8d9da4b9a0753b059c2f63d7f4a5cbc6e417d..60a1fc60028018a96e7571cfec67f94d98829210 100644 (file)
 #define FOTA_DELTA_FILENAME "delta.tar"
 #define FOTA_DELTA_COMPRESSED_FILENAME "delta.tar.gz"
 
-#define FOTA_DELTA_BUILD_STRING_DIR "/tmp"
-#define FOTA_DELTA_BUILD_STRING_FILENAME "build_string.txt"
-#define FOTA_DELTA_BUILD_STRING_PATH FOTA_DELTA_BUILD_STRING_DIR "/" FOTA_DELTA_BUILD_STRING_FILENAME
-#define FOTA_DELTA_BUILD_STRING_FULL_DELTA_PREFIX "0.0@"
-
 #define FOTA_STATUS_DIR "/opt/data/update"
 #define FOTA_STATUS_FLAG_PATH FOTA_STATUS_DIR "/is-first-boot-after-fota"
 
+#define FOTA_DELTA_UPDATE_INFO_DIR "/tmp"
+#define FOTA_DELTA_UPDATE_INFO_FILENAME "update-info.ini"
+#define FOTA_DELTA_UPDATE_INFO_PATH FOTA_DELTA_UPDATE_INFO_DIR "/" FOTA_DELTA_UPDATE_INFO_FILENAME
+#define DELTA_VERIFIER_BIN "/usr/bin/delta-verifier"
+#define DELTA_VERIFIER_BIN_LONG_ARG "--update_info_path"
+
 #define FOTA_EVENT_SIZE 3
 
 /* Enum */
@@ -43,10 +44,6 @@ int fota_client_info_checker_init(void);
 int fota_client_info_checker_fini(void);
 char *fota_client_info_get_appid(void);
 
-int fota_info_checker_init(void);
-int fota_info_checker_fini(void);
-char *fota_info_get_build_string(void);
-
 int fota_installer_execute(pid_t pid);
 
 void fota_storage_checker_plug(int, const char *);
index ca50249f0c0a180f69a0b390fed654a1f4478c04..9eed6a3b9d566c984bea0b57d456c0c841c22c1e 100644 (file)
@@ -9,23 +9,9 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name)
        int ret = 0;
        bool is_appropriate = false;
        char buf[MAX_BUFFER_SIZE] = {0, };
-       char *old_build_string = NULL;
        gchar *storage_delta_path = NULL;
 
-       /* 1. Check storage support current image */
-       old_build_string = fota_info_get_build_string();
-       if (old_build_string == NULL) {
-               _FLOGE("Failed to get current image build string");
-               goto verify_destroy;
-       }
-
-       if (g_str_has_prefix(folder_name, old_build_string) != TRUE) {
-               _FLOGI("Storage doesn't support current image(%s), folder name(%s)",
-                               old_build_string, folder_name);
-               goto verify_destroy;
-       }
-
-       /* 2. Check storage have delta.tar */
+       /* 1. Check storage have delta.tar */
        storage_delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILENAME, NULL);
        if (!g_file_test(storage_delta_path, G_FILE_TEST_EXISTS)) {
                gchar *tmp_storage_delta_path = storage_delta_path;
@@ -38,18 +24,20 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name)
                }
        }
 
-       /* 3. Check storage have appropriate delta */
-       ret = util_file_untar(storage_delta_path, FOTA_DELTA_BUILD_STRING_DIR, FOTA_DELTA_BUILD_STRING_FILENAME);
-       if (ret < 0)
+       /* 2. Check storage have appropriate delta */
+       ret = util_file_untar(storage_delta_path, FOTA_DELTA_UPDATE_INFO_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME);
+       if (ret < 0) {
                goto verify_destroy;
+       }
 
-       ret = util_file_read_single_line(FOTA_DELTA_BUILD_STRING_PATH, buf);
-       if (ret < 0)
-               goto verify_destroy;
+       snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH);
+       ret = system(buf);
 
-       if (g_str_equal(folder_name, buf) != TRUE) {
-               _FLOGI("Storage doesn't have appropriate delta(%s), delta build string(%s)",
-                               folder_name, buf);
+       if (ret < 0) {
+               _FLOGE("Delta verification failed due to an error [return code: %d].", ret);
+               goto verify_destroy;
+       } else if (ret > 0) {
+               _FLOGI("The delta at [%s] is not compatible with this device [return code: %d].", storage_delta_path, ret);
                goto verify_destroy;
        }
 
@@ -57,8 +45,6 @@ gchar *fota_storage_find_delta(const char* mount_path, const char *folder_name)
        is_appropriate = true;
 
 verify_destroy:
-       util_file_remove(FOTA_DELTA_BUILD_STRING_PATH);
-
        if (!is_appropriate && storage_delta_path) {
                free(storage_delta_path);
                storage_delta_path = NULL;
index efd17274fd47b914e0b2506b34a111564bfda4bf..b17aa13f038a91c1f7058889edc9ce8554bcf463 100644 (file)
@@ -40,12 +40,6 @@ int main(int argc, char *argv[])
                goto main_destroy;
        }
 
-       ret = fota_info_checker_init();
-       if (ret < 0) {
-               _CLOGE("Failed to initialize fota info checker : %d", ret);
-               goto main_destroy;
-       }
-
        /* Dbus */
        ret = dbus_manager_init();
        if (ret < 0) {
@@ -75,10 +69,6 @@ main_destroy:
        if (ret < 0)
                _CLOGW("Failed to finalize fota client info checker : %d", ret);
 
-       ret = fota_info_checker_fini();
-       if (ret < 0)
-               _CLOGW("Failed to finalize fota info checker : %d", ret);
-
        /* Dbus */
        ret = dbus_manager_fini();
        if (ret < 0)