Don't use printf in uv

This commit is contained in:
Aoran Zeng 2025-07-26 20:49:47 +08:00
parent ff3e80c6ee
commit 61944e01de
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
2 changed files with 16 additions and 31 deletions

View File

@ -7,7 +7,7 @@
* |
* Created On : <2024-12-11>
* Major Revision : 1
* Last Modified : <2025-07-14>
* Last Modified : <2025-07-26>
* ------------------------------------------------------------*/
/**
@ -115,47 +115,32 @@ pl_python_uv_setsrc (char *option)
/**
* [[index]] default = true url = ".*" url = "source.url"
*/
char *update_source_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd);
update_source_cmd = xy_str_gsub (update_source_cmd, "@f@", uv_config);
update_source_cmd = xy_str_gsub (update_source_cmd, "@url@", source.url);
char *update_config_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd);
update_config_cmd = xy_str_gsub (update_config_cmd, "@f@", uv_config);
update_config_cmd = xy_str_gsub (update_config_cmd, "@url@", source.url);
char *append_source_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
char *append_config_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
char *cmd = NULL;
if (!xy_file_exist (uv_config))
{
/**
* uv_config
* run: append_source_cmd
*/
cmd = append_source_cmd;
/* 当 uv_config 不存在,直接写入文件 */
chsrc_append_to_file (source_content, uv_config);
}
else
{
if (xy_on_windows)
/* 当 uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾 */
char *cmd = xy_str_gsub (RAWSTR_pl_python_test_uv_if_set_source, "@f@", uv_config);
chsrc_ensure_program ("grep");
int status = system (cmd);
if (0==status)
{
/* TODO: Windows 下替换源暂不支持 */
chsrc_note2 ("Windows 下暂不支持修改 uv.toml请手动修改配置文件");
chsrc_run (update_config_cmd, RunOpt_Default);
}
else
{
/**
* uv_config [[index]]
*/
cmd = xy_str_gsub (RAWSTR_pl_python_final_uv_cmd, "@f@", uv_config);
cmd = xy_str_gsub (cmd, "@ucmd@", update_source_cmd);
cmd = xy_str_gsub (cmd, "@acmd@", append_source_cmd);
chsrc_append_to_file (source_content, uv_config);
}
}
if (NULL==cmd)
{
chsrc_note2 (xy_strjoin (4, "请手动为 ", uv_config, "添加或修改 [[index]] 配置项的 url = ", source.url));
}
else
{
chsrc_run (cmd, RunOpt_Default);
}
if (chsrc_in_standalone_mode())
{