[bugfix][T106][bug-view-2360] Solve the problem that sync operations may affect upgrades

Only Configure:No
Affected branch:master
Affected module:fota
Self-test:Yes

Change-Id: Ia513c5f32c8659c044fd4174b1eb604d93013d02
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
index 811e7e7..20816fb 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-fota/lynq-qser-fota.cpp
@@ -39,6 +39,8 @@
 #define  SYSTEM_A  "34650"

 #define  SYSTEM_B  "39019"

 

+#define SYNC_RUNNING_FLAG "/tmp/sync_running.flag"

+#define UPDATE_ACTIVE_FLAG "/tmp/update_active.flag"

 

 #define BOOTABLE   "45227"

 #define UNBOOTABLE "47806"

@@ -125,11 +127,36 @@
 int lynq_set_sync_status(char *option_para);

 int  calculate_md5_sum( char *md5_sum,int md5_size);

 

+

+static int can_run_update() 

+{

+    if (access(SYNC_RUNNING_FLAG, F_OK) == 0) 

+    {

+        LYINFLOG("Update: Status=-2 (Sync is running, please try later)\n");

+        return -2;

+    }

+

+    return 0;

+}

+

+static int set_update_flag()

+{

+    FILE *fp = fopen(UPDATE_ACTIVE_FLAG, "w");

+    if (!fp) 

+    {

+        LYINFLOG("open update_active_flag file failed \n");

+        return -1;

+    }

+    fprintf(fp, "OTA update active");

+    fclose(fp);

+    system("sync");

+    return 0;

+}

 /*****************************************

 * @brief:rock_update_main

 * @param count [IN]:NA

 * @param sum [OUT]:NA

-* @return :success 0, failed -1

+* @return :success 0, failed -1, busy -2

 * @todo:NA

 * @see:NA

 * @warning:NA

@@ -146,8 +173,16 @@
     struct tm *localTime;

     double elapsed = 0;

     char md5_sum[48] = {0};

-

-    FILE *fp = NULL;

+    FILE *fp = NULL; 

+    

+    if(set_update_flag() != 0)

+    {

+    	return -1;

+    }

+    if(can_run_update() != 0)

+    {

+	return -2;

+    }

     fp = fopen(FOTA_FLAG_FILE,"w+");

     if(fp == NULL)

     {

@@ -474,7 +509,7 @@
 * @brief:lynq_fota_nrestart no reboot

 * @param count [IN]:NA

 * @param sum [OUT]:NA

-* @return :success 0, failed -1

+* @return :success 0, failed -1, busy -2

 * @todo:NA

 * @see:NA

 * @warning:NA

@@ -515,7 +550,7 @@
 * @brief:lynq_rock_main,upgrade done reboot

 * @param count [IN]:int first_run

 * @param sum [OUT]:NA

-* @return :success 0, failed -1

+* @return :success 0, failed -1, busy -2

 * @todo:NA

 * @see:NA

 * @warning:NA