Tried to update the applied file when second update 47/171947/1
authorsanghyuk Ko <sanghyuk.ko@samsung.com>
Mon, 4 Dec 2017 12:54:38 +0000 (21:54 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Thu, 8 Mar 2018 06:14:30 +0000 (15:14 +0900)
Files that are applied the patch during the update are skipped during the second update.
Files that are deleted during the update are skipped during the second update.

Change-Id: Icb563c1fc7693287232d52dd38f15d3ccf4115a7

src/ua.c

index 2418d96..49f2250 100755 (executable)
--- a/src/ua.c
+++ b/src/ua.c
@@ -72,7 +72,6 @@ FILE *__log_out_file__;
 
 static void save_result(int result);
 static void save_cause(int cause);
-static int get_last_update_status(void);
 
 /*-----------------------------------------------------------------------------
   fota_gui_update_progress
@@ -494,129 +493,6 @@ static void set_data_weight_offset(void)
 }
 
 /*-----------------------------------------------------------------------------
-  read_from_file
- ----------------------------------------------------------------------------*/
-int read_from_file(const char *path, char *buf, size_t size)
-{
-       int fd;
-       ssize_t count;
-
-       if (!path)
-               return -1;
-
-       if (size == 0)
-               return 0;
-
-       fd = open(path, O_RDONLY, 0);
-       LOG("open '%s'\n", path);
-       if (fd == -1) {
-               LOG("Could not open '%s'", path);
-               return -1;
-       }
-
-       count = read(fd, buf, size);
-       if (count > 0) {
-               count = (count < (ssize_t)size) ? count : ((ssize_t)size - 1);
-               while (count > 0 && buf[count - 1] == '\n')
-                       count--;
-               buf[count] = '\0';
-       } else {
-               buf[0] = '\0';
-       }
-       LOG("read '%s'\n", buf);
-
-       close(fd);
-
-       return (int)count;
-}
-
-
-/*-----------------------------------------------------------------------------
-  write_to_file
- ----------------------------------------------------------------------------*/
-/* size is the contents size, not buf size
-   buf size should be larger than contents size */
-int write_to_file(const char *path, char *buf, size_t size)
-{
-       int fd;
-       ssize_t count;
-
-       if (!path)
-               return -1;
-
-       fd = open(path, O_WRONLY | O_CREAT, S_IRWXU);
-       LOG("open '%s'\n", path);
-
-       if (fd == -1) {
-               LOG("Could not open '%s'\n", path);
-               return -1;
-       }
-
-       count = write(fd, buf, size);
-       LOG("write '%s'\n", buf);
-
-       if (fsync(fd) < 0)
-               LOG("fsync failed.\n");
-
-       close(fd);
-
-       if (size != count) {
-               LOG("Could not write to '%s'\n", path);
-               return -1;
-       }
-
-       return 0;
-}
-
-/*-----------------------------------------------------------------------------
-  write_num_to_file
- ----------------------------------------------------------------------------*/
-int write_num_to_file(const char *path, int num)
-{
-       char num_str[16];
-
-       snprintf(num_str, sizeof(num_str), "%d", num);
-       return write_to_file(path, num_str, strlen(num_str));
-}
-
-/*-----------------------------------------------------------------------------
-  get_last_update_status
- ----------------------------------------------------------------------------*/
-static int get_last_update_status(void)
-{
-       /*
-           if status file does not exist, status = UP_START_NONE.
-           if status file exist, read status from file.
-       */
-       char buf[256];
-       int status = UP_START_NONE;
-
-       if (check_existence(fota_status_path) == 0)
-               return UP_START_NONE;
-
-       if (read_from_file(fota_status_path, buf, sizeof(buf)) < 0)
-               return UP_START_NONE;
-
-       status = atoi(buf);
-       if ((status > UP_START_NONE) && (status < s_part_num))
-               return status;
-       else
-               return UP_START_NONE;
-}
-
-/*-----------------------------------------------------------------------------
-  set_last_update_status
- ----------------------------------------------------------------------------*/
-static void set_last_update_status(int status)
-{
-       /*
-           if status file exist, write status to file.
-           if status file does not exist, create file and write status to file.
-       */
-       write_num_to_file(fota_status_path, status);
-}
-
-/*-----------------------------------------------------------------------------
   get_time_stamp
  ----------------------------------------------------------------------------*/
 static char ts[256];
@@ -642,6 +518,7 @@ int update_all()
        int item_size = 0;
        int last_update_status = UP_START_NONE;
        int update_status = UP_START_NONE;
+       int del_type = 0;       // delta type
        int part_idx = UA_PARTI_MAX;
        unsigned int update_type = 0;
        unsigned long ui32Operation = UI_OP_SCOUT;
@@ -697,8 +574,9 @@ int update_all()
                        s_part_info[i].ua_subject_name);
        }
 
-       last_update_status = get_last_update_status();
-       LOG("Updatea_all() Last Update status To start with [%d] \n", last_update_status);
+       last_update_status = SS_Get_last_update_status();
+       del_type = SS_Get_last_update_del_type();
+       LOG("last_update_status: [%d], del_type: [%d] \n", last_update_status, del_type);
        /* Verify */
        if (last_update_status == UP_START_NONE) {
                for (part_idx = 0; part_idx < s_part_num; part_idx++) {
@@ -706,7 +584,6 @@ int update_all()
                                get_time_stamp();
                                LOG("[%s] Verify %s ..............................................................\n", ts,
                                        s_part_info[part_idx].ua_parti_name);
-
                                update_type = s_update_cfg[part_idx].update_type;
                                if (update_type == FULL_IMG)
                                        ret = verify_Full_Image(part_idx);
@@ -748,7 +625,7 @@ int update_all()
                                LOG("[%s] Update %s ..............................................................\n", ts,
                                        s_part_info[part_idx].ua_parti_name);
 
-                               set_last_update_status(update_status);
+                               SS_Set_last_update_status(update_status, del_type);
 
                                update_type = s_update_cfg[part_idx].update_type;
                                if (update_type == FULL_IMG)
@@ -769,12 +646,13 @@ int update_all()
                                        goto CleanUp;
                                }
                                s_update_data[part_idx].update_check = 1;
+                               del_type = 0;
                        }
                }
        }
 
        if (part_idx == s_part_num)
-               set_last_update_status(s_part_num);
+               SS_Set_last_update_status(s_part_num, 0);
 
        get_time_stamp();
        LOG("[%s] Update End ..............................................................\n", ts);