VentoyPlugson: Add Windows duplicate file path check for different upper/lower case.

pull/2085/head
longpanda 2 years ago
parent 9b7d6cbc3d
commit 3e75b2df3b

@ -638,7 +638,8 @@ int CheckRuntimeEnvironment(char Letter, ventoy_disk *disk)
return 1; return 1;
} }
if (_stricmp(FsName, "NTFS") == 0) /* Fix: enable for all file system on Windows */
/* if (_stricmp(FsName, "NTFS") == 0) */
{ {
disk->pathcase = 1; disk->pathcase = 1;
} }

@ -21,6 +21,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
@ -97,6 +98,9 @@ static char *g_pub_save_buffer = NULL;
static pthread_mutex_t g_api_mutex; static pthread_mutex_t g_api_mutex;
static struct mg_context *g_ventoy_http_ctx = NULL; static struct mg_context *g_ventoy_http_ctx = NULL;
#define ventoy_is_real_exist_common(xpath, xnode, xtype) \
ventoy_path_is_real_exist(xpath, xnode, offsetof(xtype, path), offsetof(xtype, next))
static int ventoy_is_kbd_valid(const char *key) static int ventoy_is_kbd_valid(const char *key)
{ {
int i = 0; int i = 0;
@ -170,6 +174,40 @@ static void ventoy_free_path_node_list(path_node *list)
} }
} }
static int ventoy_path_is_real_exist(const char *path, void *head, size_t pathoff, size_t nextoff)
{
char *node = NULL;
const char *nodepath = NULL;
const char *realpath = NULL;
char pathbuf[MAX_PATH];
if (strchr(path, '*'))
{
return 0;
}
realpath = ventoy_real_path(path);
scnprintf(pathbuf, sizeof(pathbuf), "%s", realpath);
node = (char *)head;
while (node)
{
nodepath = node + pathoff;
if (NULL == strchr(nodepath, '*'))
{
realpath = ventoy_real_path(nodepath);
if (strcmp(pathbuf, realpath) == 0)
{
return 1;
}
}
memcpy(&node, node + nextoff, sizeof(node));
}
return 0;
}
static path_node * ventoy_path_node_add_array(VTOY_JSON *array) static path_node * ventoy_path_node_add_array(VTOY_JSON *array)
{ {
path_node *head = NULL; path_node *head = NULL;
@ -913,16 +951,15 @@ static int ventoy_api_save_theme(struct mg_connection *conn, VTOY_JSON *json)
return 0; return 0;
} }
static int ventoy_api_theme_add_file(struct mg_connection *conn, VTOY_JSON *json) static int ventoy_api_theme_add_file(struct mg_connection *conn, VTOY_JSON *json)
{ {
int ret; int ret;
int index = 0; int index = 0;
const char *path = NULL; const char *path = NULL;
const char *realpath = NULL;
path_node *node = NULL; path_node *node = NULL;
path_node *cur = NULL; path_node *cur = NULL;
data_theme *data = NULL; data_theme *data = NULL;
char pathbuf[MAX_PATH];
vtoy_json_get_int(json, "index", &index); vtoy_json_get_int(json, "index", &index);
data = g_data_theme + index; data = g_data_theme + index;
@ -930,19 +967,12 @@ static int ventoy_api_theme_add_file(struct mg_connection *conn, VTOY_JSON *json
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path) if (path)
{ {
realpath = ventoy_real_path(path); if (ventoy_is_real_exist_common(path, data->filelist, path_node))
scnprintf(pathbuf, sizeof(pathbuf), "%s", realpath);
for (node = data->filelist; node; node = node->next)
{ {
realpath = ventoy_real_path(node->path); ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
if (strcmp(pathbuf, realpath) == 0) return 0;
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
} }
node = zalloc(sizeof(path_node)); node = zalloc(sizeof(path_node));
if (node) if (node)
{ {
@ -989,17 +1019,14 @@ static int ventoy_api_theme_del_file(struct mg_connection *conn, VTOY_JSON *json
return 0; return 0;
} }
static int ventoy_api_theme_add_font(struct mg_connection *conn, VTOY_JSON *json) static int ventoy_api_theme_add_font(struct mg_connection *conn, VTOY_JSON *json)
{ {
int ret; int ret;
int index = 0; int index = 0;
const char *path = NULL; const char *path = NULL;
const char *realpath = NULL;
path_node *node = NULL; path_node *node = NULL;
path_node *cur = NULL; path_node *cur = NULL;
data_theme *data = NULL; data_theme *data = NULL;
char pathbuf[MAX_PATH];
vtoy_json_get_int(json, "index", &index); vtoy_json_get_int(json, "index", &index);
data = g_data_theme + index; data = g_data_theme + index;
@ -1007,19 +1034,12 @@ static int ventoy_api_theme_add_font(struct mg_connection *conn, VTOY_JSON *json
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path) if (path)
{ {
realpath = ventoy_real_path(path); if (ventoy_is_real_exist_common(path, data->fontslist, path_node))
scnprintf(pathbuf, sizeof(pathbuf), "%s", realpath);
for (node = data->fontslist; node; node = node->next)
{ {
realpath = ventoy_real_path(node->path); ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
if (strcmp(pathbuf, realpath) == 0) return 0;
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
} }
node = zalloc(sizeof(path_node)); node = zalloc(sizeof(path_node));
if (node) if (node)
{ {
@ -1222,6 +1242,12 @@ static int ventoy_api_alias_add(struct mg_connection *conn, VTOY_JSON *json)
alias = VTOY_JSON_STR_EX("alias"); alias = VTOY_JSON_STR_EX("alias");
if (path && alias) if (path && alias)
{ {
if (ventoy_is_real_exist_common(path, data->list, data_alias_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(data_alias_node)); node = zalloc(sizeof(data_alias_node));
if (node) if (node)
{ {
@ -1467,6 +1493,12 @@ static int ventoy_api_tip_add(struct mg_connection *conn, VTOY_JSON *json)
tip = VTOY_JSON_STR_EX("tip"); tip = VTOY_JSON_STR_EX("tip");
if (path && tip) if (path && tip)
{ {
if (ventoy_is_real_exist_common(path, data->list, data_tip_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(data_tip_node)); node = zalloc(sizeof(data_tip_node));
if (node) if (node)
{ {
@ -1816,6 +1848,12 @@ static int ventoy_api_auto_memdisk_add(struct mg_connection *conn, VTOY_JSON *js
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path) if (path)
{ {
if (ventoy_is_real_exist_common(path, data->list, path_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(path_node)); node = zalloc(sizeof(path_node));
if (node) if (node)
{ {
@ -1998,6 +2036,12 @@ static int ventoy_api_image_list_add(struct mg_connection *conn, VTOY_JSON *json
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path) if (path)
{ {
if (ventoy_is_real_exist_common(path, data->list, path_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(path_node)); node = zalloc(sizeof(path_node));
if (node) if (node)
{ {
@ -2253,6 +2297,12 @@ static int ventoy_api_password_add(struct mg_connection *conn, VTOY_JSON *json)
pwd = VTOY_JSON_STR_EX("pwd"); pwd = VTOY_JSON_STR_EX("pwd");
if (path && pwd) if (path && pwd)
{ {
if (ventoy_is_real_exist_common(path, data->list, menu_password))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(menu_password)); node = zalloc(sizeof(menu_password));
if (node) if (node)
{ {
@ -2658,6 +2708,12 @@ static int ventoy_api_dud_add(struct mg_connection *conn, VTOY_JSON *json)
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path && array) if (path && array)
{ {
if (ventoy_is_real_exist_common(path, data->list, dud_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(dud_node)); node = zalloc(sizeof(dud_node));
if (node) if (node)
{ {
@ -3013,6 +3069,12 @@ static int ventoy_api_auto_install_add(struct mg_connection *conn, VTOY_JSON *js
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path && array) if (path && array)
{ {
if (ventoy_is_real_exist_common(path, data->list, auto_install_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(auto_install_node)); node = zalloc(sizeof(auto_install_node));
if (node) if (node)
{ {
@ -3355,6 +3417,12 @@ static int ventoy_api_persistence_add(struct mg_connection *conn, VTOY_JSON *jso
path = VTOY_JSON_STR_EX("path"); path = VTOY_JSON_STR_EX("path");
if (path && array) if (path && array)
{ {
if (ventoy_is_real_exist_common(path, data->list, persistence_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(persistence_node)); node = zalloc(sizeof(persistence_node));
if (node) if (node)
{ {
@ -3648,6 +3716,12 @@ static int ventoy_api_injection_add(struct mg_connection *conn, VTOY_JSON *json)
archive = VTOY_JSON_STR_EX("archive"); archive = VTOY_JSON_STR_EX("archive");
if (path && archive) if (path && archive)
{ {
if (ventoy_is_real_exist_common(path, data->list, injection_node))
{
ventoy_json_result(conn, VTOY_JSON_DUPLICATE);
return 0;
}
node = zalloc(sizeof(injection_node)); node = zalloc(sizeof(injection_node));
if (node) if (node)
{ {

@ -1 +1 @@
20221220 18:30:51 20221221 12:11:59

@ -757,7 +757,7 @@
<footer class="main-footer"> <footer class="main-footer">
<div class="pull-right hidden-xs"> <div class="pull-right hidden-xs">
<b id="plugson_build_date">20221220 19:41:37</b> <b id="plugson_build_date">20221221 12:11:59</b>
</div> </div>
<strong><a href="https://www.ventoy.net" target="_blank">https://www.ventoy.net</a></strong> <strong><a href="https://www.ventoy.net" target="_blank">https://www.ventoy.net</a></strong>
</footer> </footer>
@ -777,10 +777,10 @@
<script src="/static/js/jQuery-2.1.4.min.js"></script> <script src="/static/js/jQuery-2.1.4.min.js"></script>
<!-- jquery validate --> <!-- jquery validate -->
<script src="/static/js/jquery.validate.min.js"></script> <script src="/static/js/jquery.validate.min.js"></script>
<script src="/static/js/jquery.validate.vtoymethods.js?v=102"></script> <script src="/static/js/jquery.validate.vtoymethods.js?v=103"></script>
<script src="/static/js/jquery.vtoy.alert.js?v=102"></script> <script src="/static/js/jquery.vtoy.alert.js?v=103"></script>
<script src="/static/js/vtoy.js?v=102"></script> <script src="/static/js/vtoy.js?v=103"></script>
<script src="/static/js/md5.min.js"></script> <script src="/static/js/md5.min.js"></script>
<!-- Bootstrap 3.3.5 --> <!-- Bootstrap 3.3.5 -->

@ -359,9 +359,13 @@
template: call_array, template: call_array,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillAutoInsTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillAutoInsTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -131,9 +131,13 @@
index: current_tab_index, index: current_tab_index,
path: data.path, path: data.path,
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillMemdiskTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillMemdiskTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -203,9 +203,13 @@
dud: call_array, dud: call_array,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillDudTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillDudTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -221,9 +221,13 @@
index: current_tab_index, index: current_tab_index,
path: data.path, path: data.path,
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillImageListTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillImageListTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -158,9 +158,13 @@
archive: data.archive, archive: data.archive,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillInjectionTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillInjectionTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -152,9 +152,13 @@
alias: data.alias, alias: data.alias,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillAliasTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillAliasTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -178,9 +178,13 @@
class: data.class, class: data.class,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillClassTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillClassTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -244,9 +244,13 @@
tip: data.tip, tip: data.tip,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillTipTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillTipTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -464,9 +464,13 @@ function VtoySetPassword(common, type, cb, data) {
path: data.path, path: data.path,
pwd: data.pwd pwd: data.pwd
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillMenuPwdTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillMenuPwdTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

@ -358,9 +358,13 @@
backend: call_array, backend: call_array,
type: type type: type
}, function(e) { }, function(e) {
list.push(data); if (e.result === 'success') {
FillPersistenceTable(list); list.push(data);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS); FillPersistenceTable(list);
Message.success(g_vtoy_cur_language.STR_SAVE_SUCCESS);
} else if (e.result === 'duplicate') {
Message.error(g_vtoy_cur_language.STR_DUPLICATE_PATH);
}
}); });
} }

Loading…
Cancel
Save