]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - Plugson/src/Web/ventoy_http.c
Fix a bug when rhel based distribution has an external kickstart file. (#1717)
[Ventoy.git] / Plugson / src / Web / ventoy_http.c
index 96a6fa51589930db652db33ac674371b74659dfe..a84ac426fd440c8cb2ecbc39052bb6a36ba028ee 100644 (file)
@@ -322,8 +322,10 @@ static int ventoy_api_sysinfo(struct mg_connection *conn, VTOY_JSON *json)
     //read clear
     VTOY_JSON_FMT_SINT("syntax_error", g_sysinfo.syntax_error);
     g_sysinfo.syntax_error = 0;
-
-
+    
+    VTOY_JSON_FMT_SINT("invalid_config", g_sysinfo.invalid_config);
+    g_sysinfo.invalid_config = 0;
+    
     #if defined(_MSC_VER) || defined(WIN32)
     VTOY_JSON_FMT_STRN("os", "windows");
     #else
@@ -346,6 +348,8 @@ static int ventoy_api_handshake(struct mg_connection *conn, VTOY_JSON *json)
     VTOY_JSON_FMT_BEGIN(pos, JSON_BUFFER, JSON_BUF_MAX);
     VTOY_JSON_FMT_OBJ_BEGIN();
     VTOY_JSON_FMT_SINT("status", 0);
+    VTOY_JSON_FMT_SINT("save_error", g_sysinfo.config_save_error);
+    g_sysinfo.config_save_error = 0;
     VTOY_JSON_FMT_OBJ_END();
     VTOY_JSON_FMT_END(pos);
 
@@ -1772,7 +1776,9 @@ int ventoy_data_cmp_image_list(data_image_list *data1, data_image_list *data2)
 int ventoy_data_save_image_list(data_image_list *data, const char *title, char *buf, int buflen)
 {
     int pos = 0;
+    int prelen;
     path_node *node = NULL;
+    char newtitle[64];
 
     (void)title;
 
@@ -1780,17 +1786,20 @@ int ventoy_data_save_image_list(data_image_list *data, const char *title, char *
     {
         return 0;
     }
-    
+
+    prelen = (int)strlen("image_list");
+
     VTOY_JSON_FMT_BEGIN(pos, buf, buflen);
 
     if (data->type == 0)
     {
-        VTOY_JSON_FMT_KEY_L(L1, "image_list");
+        scnprintf(newtitle, sizeof(newtitle), "image_list%s", title + prelen);
     }
     else
     {
-        VTOY_JSON_FMT_KEY_L(L1, "image_blacklist");
+        scnprintf(newtitle, sizeof(newtitle), "image_blacklist%s", title + prelen);
     }
+    VTOY_JSON_FMT_KEY_L(L1, newtitle);
     
     VTOY_JSON_FMT_ARY_BEGIN_N();
 
@@ -3569,6 +3578,7 @@ int ventoy_http_writeback(void)
     if (ret)
     {
         vlog("Failed to write ventoy.json file.\n");
+        g_sysinfo.config_save_error = 1;
     }
 
     return 0;
@@ -4917,6 +4927,7 @@ static int ventoy_load_old_json(const char *filename)
     unsigned char *start = NULL;
     VTOY_JSON *json = NULL;
     VTOY_JSON *node = NULL;
+    VTOY_JSON *next = NULL;
 
     ret = ventoy_read_file_to_buf(filename, 4, (void **)&buffer, &buflen);
     if (ret)
@@ -4950,6 +4961,18 @@ static int ventoy_load_old_json(const char *filename)
     {
         vlog("parse ventoy.json success\n");
 
+        for (node = json->pstChild; node; node = node->pstNext)
+        for (next = node->pstNext; next; next = next->pstNext)
+        {
+            if (node->pcName && next->pcName && strcmp(node->pcName, next->pcName) == 0)
+            {
+                vlog("ventoy.json contains duplicate key <%s>.\n", node->pcName);
+                g_sysinfo.invalid_config = 1;
+                ret = 1;
+                goto end;
+            }
+        }
+
         for (node = json->pstChild; node; node = node->pstNext)
         {
             ventoy_parse_json(control);
@@ -4975,6 +4998,7 @@ static int ventoy_load_old_json(const char *filename)
         ret = 1;
     }
 
+end:
     vtoy_json_destroy(json);
 
     free(buffer);