else
_W("vconf_ignore_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret);
- _I("Success to get bootstatus success, try process fota event");
+ _FLOGI("Success to get bootstatus success, try process fota event");
ret = fota_client_controller_process_event();
if (ret < 0)
- _E("Failed to process fota client event : %d", ret);
+ _FLOGE("Failed to process fota client event : %d", ret);
_RLOGI("Success to get bootstatus success, try process recovery event");
ret = recovery_client_controller_process_event();
#include "fota/fota-manager.h"
#include "update-manager.h"
-int fota_controller_verify_delta(const char *delta_path)
-{
- int ret = 0, status = 0;
- char buf[MAX_BUFFER_SIZE] = {0, };
- char *build_id = NULL;
-
- if (g_file_test(delta_path, G_FILE_TEST_EXISTS)) {
- _I("Found delta in %s, start process to verify", delta_path);
-
- ret = util_file_untar(delta_path, BUILD_ID_DIR, BUILD_ID_FILE);
- if (ret < 0) {
- _E("Failed to fetch %s from delta : %d", BUILD_ID_FILE, ret);
- status = -1;
- goto verify_destroy;
- }
-
- build_id = fota_info_get_build_string();
- if (build_id == NULL) {
- _E("Failed to get current build id");
- status = -1;
- goto verify_destroy;
- }
-
- ret = util_file_read_line(BUILD_ID_PATH, buf);
- if (ret < 0) {
- _E("Failed to read delta build id : %d", ret);
- status = -1;
- goto verify_destroy;
- }
-
- if (g_strrstr(buf, build_id) != NULL) {
- _I("Delta build id matched : %s", build_id);
- } else {
- _I("Delta build id unmatched, current : %s, delta : %s",
- build_id, buf);
- status = 1;
- }
- } else {
- _I("Not found delta in %s", delta_path);
- status = 2;
- }
-
-verify_destroy:
- ret = remove(BUILD_ID_PATH);
- if (ret < 0)
- _W("Failed to remove %s : %m", BUILD_ID_PATH);
-
- return status;
-}
-
int fota_controller_setup_delta()
{
int ret = 0, status = 0;
- char *appid = NULL;
+ char *appid = NULL, *build_string = NULL;
gchar *shared_path = NULL;
ret = util_file_mkdir(FOTA_DIR);
goto delta_destroy;
}
+ build_string = fota_info_get_build_string();
+ if (build_string == NULL) {
+ _E("Failed to get build string");
+ status = -1;
+ goto delta_destroy;
+ }
+
ret = remove(FOTA_DELTA_PATH);
if (ret < 0 && errno != ENOENT)
_W("Failed to remove exist link : %m");
shared_path = g_strjoin("/", SHARED_DIR, appid, SHARED_DATA_DIR, FOTA_DELTA_FILE, NULL);
- ret = fota_controller_verify_delta(shared_path);
+ ret = fota_delta_verify(shared_path, build_string, NULL);
if (ret != 0) {
_E("Failed to verify delta : %d", ret);
status = -1;
--- /dev/null
+#include "fota-manager.h"
+#include "../update-manager.h"
+
+int fota_delta_verify(const char *path, const char *old_build_string, const char *new_build_string)
+{
+ int ret = 0, status = 0;
+ char buf[MAX_BUFFER_SIZE] = {0, };
+ FILE *fp = NULL;
+
+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
+ _FLOGI("Not found delta in %s", path);
+ status = 1;
+ goto verify_destroy;
+ }
+
+ if (old_build_string == NULL) {
+ _FLOGE("Failed to try verify, old build string must be passed");
+ status = -1;
+ goto verify_destroy;
+ }
+
+ _FLOGI("Found delta in %s, start process to verify", path);
+ ret = util_file_untar(path, BUILD_ID_DIR, BUILD_ID_FILE);
+ if (ret < 0) {
+ _FLOGE("Failed to fetch %s from delta : %d", BUILD_ID_FILE, ret);
+ status = -1;
+ goto verify_destroy;
+ }
+
+ fp = fopen(BUILD_ID_PATH, "r");
+ if (fp == NULL) {
+ _FLOGE("Failed to open : %s", BUILD_ID_PATH);
+ status = -1;
+ goto verify_destroy;
+ }
+
+ if (fgets(buf, MAX_BUFFER_SIZE, fp) == NULL) {
+ _FLOGE("Failed to read : %s", BUILD_ID_PATH);
+ status = -1;
+ goto verify_destroy;
+ }
+
+ if (g_strrstr(buf, old_build_string) == NULL) {
+ _FLOGI("Unmatched occur, old_build_string : %s, delta : %s", old_build_string, buf);
+ status = 2;
+ goto verify_destroy;
+ }
+
+ if (new_build_string != NULL) {
+ if (fgets(buf, MAX_BUFFER_SIZE, fp) == NULL) {
+ _FLOGE("Failed to read : %s", BUILD_ID_PATH);
+ status = -1;
+ goto verify_destroy;
+ }
+
+ if (g_strrstr(buf, new_build_string) == NULL) {
+ _FLOGI("Unmatched occur, new_build_string : %s, delta : %s", new_build_string, buf);
+ status = 3;
+ goto verify_destroy;
+ }
+ }
+
+ _FLOGI("Success to verify %s, old : %s, new : %s", path, old_build_string, new_build_string);
+
+verify_destroy:
+ ret = remove(BUILD_ID_PATH);
+ if (ret < 0)
+ _FLOGW("Failed to remove %s : %m", BUILD_ID_PATH);
+
+ if (!fp)
+ fclose(fp);
+
+ return status;
+}
\ No newline at end of file
#define FOTA_EVENT_SIZE 3
+#define FOTA_LOCAL_FOLDER_TOKEN "@"
+
/* Enum */
typedef enum {
FOTA_EVENT_PLUG = 0,
int fota_client_info_checker_fini(void);
char *fota_client_info_get_appid(void);
+int fota_delta_verify(const char *, const char *, const char *);
+
int fota_info_checker_init(void);
int fota_info_checker_fini(void);
char *fota_info_get_build_string(void);
return 0;
}
- ret = util_file_read_line(STATUS_RESULT_PATH, buf);
+ ret = util_file_read_single_line(STATUS_RESULT_PATH, buf);
if (ret < 0) {
_FLOGE("Failed to read fota result : %d", ret);
return -1;
static int fota_storage_id = -1;
+int fota_storage_verify_delta(const char* mount_path, const char *folder_name, gchar **delta_path)
+{
+ int ret = 0, status = 0;
+ char *old_build_string = NULL;
+ gchar *new_build_string = NULL, *path = NULL;
+
+ old_build_string = fota_info_get_build_string();
+ if (old_build_string == NULL) {
+ _FLOGE("Failed to get build string");
+ status = -1;
+ goto verify_destroy;
+ }
+
+ if (g_str_has_prefix(folder_name, old_build_string) != TRUE) {
+ _FLOGI("Folder %s is not start with %s, pass", folder_name, old_build_string);
+ goto verify_destroy;
+ }
+
+ new_build_string = strstr(folder_name, FOTA_LOCAL_FOLDER_TOKEN);
+ if (new_build_string == NULL) {
+ _FLOGI("Folder %s doesn't have token : %s", folder_name, FOTA_LOCAL_FOLDER_TOKEN);
+ goto verify_destroy;
+ }
+ new_build_string = new_build_string + 1;
+
+ path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL);
+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
+ _FLOGI("Folder %s doesn't have delta.tar", folder_name);
+ goto verify_destroy;
+ }
+
+ ret = fota_delta_verify(path, old_build_string, new_build_string);
+ if (ret < 0) {
+ status = -1;
+ goto verify_destroy;
+ }
+ else if (ret > 0) {
+ goto verify_destroy;
+ }
+
+ *delta_path = path;
+
+verify_destroy:
+ if (status != 0) {
+ g_free(path);
+ }
+
+ return status;
+}
+
int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path)
{
- int status = 0;
- char *build_id = NULL;
+ int ret = 0, status = 0;
const gchar *folder_name = NULL;
GFile *mount = NULL;
GFileEnumerator *enumerator = NULL;
goto search_destroy;
}
- build_id = fota_info_get_build_string();
- if (build_id == NULL) {
- _FLOGE("Failed to get build id");
- status = -1;
- goto search_destroy;
- }
-
while ((info = g_file_enumerator_next_file(enumerator, NULL, NULL)) != NULL) {
- if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY)
+ if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY) {
+ g_object_unref(info);
continue;
+ }
folder_name = g_file_info_get_name(info);
- if (g_str_has_prefix(folder_name, build_id) == TRUE) {
- *delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL);
- break;
+ ret = fota_storage_verify_delta(mount_path, folder_name, delta_path);
+ if (ret < 0) {
+ _FLOGE("Failed to verify delta : %d, folder : %s", ret, folder_name);
+ status = -1;
}
g_object_unref(info);
}
- if (*delta_path != NULL) {
- _FLOGI("Success to find delta path : %s", *delta_path);
- } else {
- _FLOGI("Failed to find delta path with prefix %s", build_id);
- status = 1;
- }
-
search_destroy:
if (enumerator)
g_object_unref(enumerator);
_FLOGI("Storage mounted with %s, start process to check local delta", mount_path);
ret = fota_storage_search_delta_path(mount_path, &delta_path);
- if (ret != 0) {
+ if (ret < 0) {
_FLOGE("Failed to find delta path : %d", ret);
goto plug_destroy;
}
- ret = fota_controller_verify_delta(delta_path);
- if (ret != 0) {
- _FLOGE("Failed to verify delta : %d", ret);
+ if (delta_path == NULL) {
+ _FLOGI("Not found matched delta in %s", mount_path);
goto plug_destroy;
}
image_path = g_strjoin("/", mount_path, RECOVERY_IMAGE_FILE, NULL);
ret = recovery_storage_search_image(image_path);
- if (ret != 0) {
+ if (ret < 0) {
_RLOGE("Failed to find delta path : %d", ret);
goto plug_destroy;
}
int dbus_manager_init(void);
int dbus_manager_fini(void);
-int fota_controller_verify_delta(const char *);
int fota_controller_install(void);
int fota_controller_result(void);
int util_file_mkdir(const char *);
-int util_file_read_line(const char *, char []);
+int util_file_read_single_line(const char *, char []);
int util_file_write_line(const char *, const char *);
int util_file_untar(const char *, const char *, const char *);
return 0;
}
-int util_file_read_line(const char *path, char buf[])
+int util_file_read_single_line(const char *path, char buf[])
{
int status = 0;
FILE *fp = NULL;