Add recovery storage checker 11/239811/6
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Tue, 28 Jul 2020 16:15:53 +0000 (16:15 +0000)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 31 Jul 2020 07:23:37 +0000 (07:23 +0000)
- Divide storage checker logic with common, recovery, fota

Change-Id: I10a89ab797551ce9c9650e1fe48d6e9df6d5859b
Signed-off-by: Jeon Sang-Heon <sh95.jeon@samsung.com>
update-manager/CMakeLists.txt
update-manager/common-storage-checker.c [deleted file]
update-manager/common/common-storage-checker.c [new file with mode: 0644]
update-manager/fota-storage-checker.c [deleted file]
update-manager/fota/fota-manager.h [new file with mode: 0644]
update-manager/fota/fota-storage-checker.c [new file with mode: 0644]
update-manager/main.c
update-manager/recovery/recovery-manager.h [new file with mode: 0644]
update-manager/recovery/recovery-storage-checker.c [new file with mode: 0644]

index 5d5918ade6f0ee0e4562d8c8431fe613873ba0d7..41108c1201baa0b45e8ec6af7570fa778195cf84 100644 (file)
@@ -32,7 +32,11 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BASE} -Wall -fPIE")
 INCLUDE_DIRECTORIES(${INCLUDE_DIR})
-FILE(GLOB SOURCE_FILES "${SOURCE_DIR}/*.h" "${SOURCE_DIR}/*.c" "${INCLUDE_DIR}/update-manager-*.h" "${INCLUDE_DIR}/update-manager-*.c")
+FILE(GLOB SOURCE_FILES
+               "${SOURCE_DIR}/*.h" "${SOURCE_DIR}/*.c"
+               "${SOURCE_DIR}/*/*.h" "${SOURCE_DIR}/*/*.c"
+               "${INCLUDE_DIR}/update-manager-*.h" "${INCLUDE_DIR}/update-manager-*.c"
+)
 ADD_EXECUTABLE(${PKG_NAME} ${SOURCE_FILES})
 TARGET_LINK_LIBRARIES(${PKG_NAME} ${${PKG_NAME}_LDFLAGS} "-ldl")
 INSTALL(TARGETS ${PKG_NAME} DESTINATION bin)
\ No newline at end of file
diff --git a/update-manager/common-storage-checker.c b/update-manager/common-storage-checker.c
deleted file mode 100644 (file)
index cd701a8..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "update-manager.h"
-
-void common_storage_checker_callback(int storage_id, storage_dev_e dev, storage_state_e state, const char *fstype,
-                                                                  const char *fsuuid, const char *mount_path, bool primary, int flags, void *user_data)
-{
-       switch (state) {
-       case STORAGE_STATE_UNMOUNTABLE:
-       case STORAGE_STATE_MOUNTED_READ_ONLY:
-               _D("Storage %d status : not mounted", storage_id);
-               break;
-       case STORAGE_STATE_MOUNTED:
-               _I("Storage %d status : mounted", storage_id);
-               fota_storage_checker_plug(storage_id, mount_path);
-               break;
-       case STORAGE_STATE_REMOVED:
-               _I("Storage %d status : removed", storage_id);
-               fota_storage_checker_unplug(storage_id, mount_path);
-               break;
-       default:
-               _E("Unexpected state : %d", state);
-       }
-}
-
-int common_storage_checker_init()
-{
-       int ret = 0;
-
-       _I("Start process to get storage status");
-       ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback, NULL);
-       if (ret == STORAGE_ERROR_NOT_SUPPORTED) {
-               _I("External storage is not suppported, so local update will not be supported");
-       }
-       else if (ret != STORAGE_ERROR_NONE) {
-               _E("storage_set_changed_cb failed : %d", ret);
-               return -1;
-       }
-
-       return 0;
-}
-
-int common_storage_checker_fini()
-{
-       int ret = 0;
-
-       ret = storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback);
-       if (ret != STORAGE_ERROR_NONE) {
-               _W("failed storage_unset_changed_cb : %d", ret);
-               return -1;
-       }
-
-       return 0;
-}
diff --git a/update-manager/common/common-storage-checker.c b/update-manager/common/common-storage-checker.c
new file mode 100644 (file)
index 0000000..4da4920
--- /dev/null
@@ -0,0 +1,55 @@
+#include "../recovery/recovery-manager.h"
+#include "../update-manager.h"
+
+void common_storage_checker_callback(int storage_id, storage_dev_e dev, storage_state_e state, const char *fstype,
+                                                                  const char *fsuuid, const char *mount_path, bool primary, int flags, void *user_data)
+{
+       switch (state) {
+       case STORAGE_STATE_UNMOUNTABLE:
+       case STORAGE_STATE_MOUNTED_READ_ONLY:
+               _D("Storage %d status : not mounted", storage_id);
+               break;
+       case STORAGE_STATE_MOUNTED:
+               _I("Storage %d status : mounted", storage_id);
+               fota_storage_checker_plug(storage_id, mount_path);
+               recovery_storage_checker_plug(storage_id, mount_path);
+               break;
+       case STORAGE_STATE_REMOVED:
+               _I("Storage %d status : removed", storage_id);
+               fota_storage_checker_unplug(storage_id, mount_path);
+               recovery_storage_checker_unplug(storage_id, mount_path);
+               break;
+       default:
+               _E("Unexpected state : %d", state);
+       }
+}
+
+int common_storage_checker_init()
+{
+       int ret = 0;
+
+       _I("Start process to get storage status");
+       ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback, NULL);
+       if (ret == STORAGE_ERROR_NOT_SUPPORTED) {
+               _I("External storage is not suppported, so local update will not be supported");
+       }
+       else if (ret != STORAGE_ERROR_NONE) {
+               _E("storage_set_changed_cb failed : %d", ret);
+               return -1;
+       }
+
+       return 0;
+}
+
+int common_storage_checker_fini()
+{
+       int ret = 0;
+
+       ret = storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, common_storage_checker_callback);
+       if (ret != STORAGE_ERROR_NONE) {
+               _W("failed storage_unset_changed_cb : %d", ret);
+               return -1;
+       }
+
+       return 0;
+}
diff --git a/update-manager/fota-storage-checker.c b/update-manager/fota-storage-checker.c
deleted file mode 100644 (file)
index c6f3539..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "update-manager.h"
-
-static int fota_storage_id = -1;
-
-int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path)
-{
-       int status = 0;
-       char *build_id = NULL;
-       const gchar *folder_name = NULL;
-       GFile *mount = NULL;
-       GFileEnumerator *enumerator = NULL;
-       GFileInfo *info = NULL;
-       GError* error = NULL;
-
-       mount = g_file_new_for_path(mount_path);
-       enumerator = g_file_enumerate_children(mount, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
-       if (enumerator == NULL) {
-               _E("Failed to get enumerator : %s", error->message);
-               g_clear_error(&error);
-               status = -1;
-               goto search_destroy;
-       }
-
-       build_id = fota_info_get_build_id();
-       if (build_id == NULL) {
-               _E("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)
-                       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;
-               }
-
-               g_object_unref(info);
-       }
-
-       if (*delta_path != NULL) {
-               _I("Success to find delta path : %s", *delta_path);
-       } else {
-               _I("Failed to find delta path with prefix %s", build_id);
-               status = 1;
-       }
-
-search_destroy:
-       if (enumerator)
-               g_object_unref(enumerator);
-
-       if (info)
-               g_object_unref(info);
-
-       g_object_unref(mount);
-
-       return status;
-}
-
-void fota_storage_checker_plug(int storage_id, const char *mount_path)
-{
-       int ret = 0;
-       gchar *delta_path = NULL;
-
-       _I("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) {
-               _E("Failed to find delta path : %d", ret);
-               goto process_destroy;
-       }
-
-       ret = fota_controller_verify_delta(delta_path);
-       if (ret != 0) {
-               _E("Failed to verify delta : %d", ret);
-               goto process_destroy;
-       }
-
-       ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
-       if (ret < 0) {
-               _E("Failed to add launch request : %d, key : %s, value : %s",
-                       ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
-       }
-       fota_storage_id = storage_id;
-
-process_destroy:
-       g_free(delta_path);
-}
-
-void fota_storage_checker_unplug(int storage_id, const char *mount_path)
-{
-       int ret = 0;
-       if (storage_id == fota_storage_id) {
-               ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
-               if (ret < 0) {
-                       _E("Failed to add launch request : %d, key : %s, value : %s",
-                               ret, CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
-               }
-               fota_storage_id = -1;
-       }
-}
diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c
new file mode 100644 (file)
index 0000000..744ddb8
--- /dev/null
@@ -0,0 +1,103 @@
+#include "../update-manager.h"
+
+static int fota_storage_id = -1;
+
+int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path)
+{
+       int status = 0;
+       char *build_id = NULL;
+       const gchar *folder_name = NULL;
+       GFile *mount = NULL;
+       GFileEnumerator *enumerator = NULL;
+       GFileInfo *info = NULL;
+       GError* error = NULL;
+
+       mount = g_file_new_for_path(mount_path);
+       enumerator = g_file_enumerate_children(mount, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
+       if (enumerator == NULL) {
+               _E("Failed to get enumerator : %s", error->message);
+               g_clear_error(&error);
+               status = -1;
+               goto search_destroy;
+       }
+
+       build_id = fota_info_get_build_id();
+       if (build_id == NULL) {
+               _E("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)
+                       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;
+               }
+
+               g_object_unref(info);
+       }
+
+       if (*delta_path != NULL) {
+               _I("Success to find delta path : %s", *delta_path);
+       } else {
+               _I("Failed to find delta path with prefix %s", build_id);
+               status = 1;
+       }
+
+search_destroy:
+       if (enumerator)
+               g_object_unref(enumerator);
+
+       if (info)
+               g_object_unref(info);
+
+       g_object_unref(mount);
+
+       return status;
+}
+
+void fota_storage_checker_plug(int storage_id, const char *mount_path)
+{
+       int ret = 0;
+       gchar *delta_path = NULL;
+
+       _I("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) {
+               _E("Failed to find delta path : %d", ret);
+               goto process_destroy;
+       }
+
+       ret = fota_controller_verify_delta(delta_path);
+       if (ret != 0) {
+               _E("Failed to verify delta : %d", ret);
+               goto process_destroy;
+       }
+
+       ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
+       if (ret < 0) {
+               _E("Failed to add launch request : %d, key : %s, value : %s",
+                       ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path);
+       }
+       fota_storage_id = storage_id;
+
+process_destroy:
+       g_free(delta_path);
+}
+
+void fota_storage_checker_unplug(int storage_id, const char *mount_path)
+{
+       int ret = 0;
+       if (storage_id == fota_storage_id) {
+               ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
+               if (ret < 0) {
+                       _E("Failed to add launch request : %d, key : %s, value : %s",
+                               ret, CLIENT_APP_CTRL_UNPLUG_KEY, mount_path);
+               }
+               fota_storage_id = -1;
+       }
+}
index b2390c8013746726e851a86b8fa77953109c7818..e78311ca67188f5ea74ef07c9ce5362f5f5438b7 100644 (file)
@@ -1,3 +1,4 @@
+#include "recovery/recovery-manager.h"
 #include "update-manager.h"
 
 int main(int argc, char *argv[])
diff --git a/update-manager/recovery/recovery-manager.h b/update-manager/recovery/recovery-manager.h
new file mode 100644 (file)
index 0000000..d043492
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __RECOVERY_MANAGER_H__
+#define __RECOVERY_MANAGER_H__
+
+#include <dlog.h>
+
+/* Log */
+#define RECOVERY_LOG_TAG "RECOVERY_MANAGER"
+
+#define _RLOGD(fmt, arg...) SLOG(LOG_INFO, RECOVERY_LOG_TAG, fmt, ##arg)
+#define _RLOGI(fmt, arg...) SLOG(LOG_INFO, RECOVERY_LOG_TAG, fmt, ##arg)
+#define _RLOGW(fmt, arg...) SLOG(LOG_WARN, RECOVERY_LOG_TAG, fmt, ##arg)
+#define _RLOGE(fmt, arg...) SLOG(LOG_ERROR, RECOVERY_LOG_TAG, fmt, ##arg)
+
+/* Constant */
+#define RECOVERY_CLIENT_METADATA_KEY "tizen-recovery-manager"
+#define RECOVERY_CLIENT_METADATA_VALUE "client"
+
+#define RECOVERY_IMAGE_FILE "tizen-recovery.img"
+
+/* Function */
+void recovery_storage_checker_plug(int, const char *);
+void recovery_storage_checker_unplug(int, const char *);
+
+#endif /* __RECOVERY_MANAGER_H__ */
diff --git a/update-manager/recovery/recovery-storage-checker.c b/update-manager/recovery/recovery-storage-checker.c
new file mode 100644 (file)
index 0000000..f316446
--- /dev/null
@@ -0,0 +1,38 @@
+#include "recovery-manager.h"
+#include "../update-manager.h"
+
+static int recovery_storage_id = -1;
+
+int recovery_storage_search_image(const gchar *image_path)
+{
+       if (g_file_test(image_path, G_FILE_TEST_EXISTS)) {
+               _RLOGI("Found image in %s, start process to verify", image_path);
+               return 0;
+       } else {
+               _RLOGI("Not found image in %s", image_path);
+               return -1;
+       }
+}
+
+void recovery_storage_checker_plug(int storage_id, const char *mount_path)
+{
+       int ret = 0;
+       gchar *image_path = NULL;
+
+       _RLOGI("Storage mounted with %s, start process to check recovery image", mount_path);
+       image_path = g_strjoin("/", mount_path, RECOVERY_IMAGE_FILE, NULL);
+
+       ret = recovery_storage_search_image(image_path);
+       if (ret != 0) {
+               _RLOGE("Failed to find delta path : %d", ret);
+               goto plug_destroy;
+       }
+
+plug_destroy:
+       g_free(image_path);
+}
+
+void recovery_storage_checker_unplug(int storage_id, const char *mount_path)
+{
+       recovery_storage_id = -1;
+}