Support local storage delta directory 54/237754/1
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 3 Jul 2020 16:49:19 +0000 (16:49 +0000)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 3 Jul 2020 16:49:19 +0000 (16:49 +0000)
- Support local storage delta directory : (old_version)-(new_version)/delta.tar

Change-Id: I864578a228665eb285f9f6d6971f739b0f93d37c
Signed-off-by: Jeon Sang-Heon <sh95.jeon@samsung.com>
update-manager/fota-storage-checker.c

index 895c638b1e6fc3601fbfa257800a24e04f6b53d5..87432cd187bc24318803ebba3bc40d984068b382 100644 (file)
@@ -1,19 +1,81 @@
 #include "update-manager.h"
 
+int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path)
+{
+       int status = 0;
+       char *release_version = 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);
+               status = -1;
+               goto search_destroy;
+       }
+
+       release_version = fota_info_get_release_version();
+       if (release_version == NULL) {
+               _E("Failed to get release version");
+               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, release_version) == 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", release_version);
+               status = 1;
+       }
+
+search_destroy:
+       if (error)
+               g_error_free(error);
+
+       if (enumerator)
+               g_object_unref(enumerator);
+
+       if (info)
+               g_object_unref(info);
+
+       g_object_unref(mount);
+
+       return status;
+}
+
 void fota_storage_checker_process(const char *mount_path)
 {
        int ret = 0;
        gchar *delta_path = NULL;
 
        _I("Storage mounted with %s, start process to check local delta", mount_path);
-       delta_path = g_strconcat(mount_path, "/", FOTA_DELTA_FILE, NULL);
+       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) {
+       if (ret != 0) {
                _E("Failed to verify delta : %d", ret);
                goto process_destroy;
-       } else if (ret > 0) {
-               _I("Failed to verify delta : %d", ret);
-               goto process_destroy;
        }
 
        ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path);