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

@ -1606,7 +1606,7 @@ chsrc_append_to_file (const char *str, const char *filename)
if (ret != 1) if (ret != 1)
{ {
char *msg = ENGLISH ? xy_2strjoin ("Write failed to ", file) char *msg = ENGLISH ? xy_2strjoin ("Write failed to ", file)
: xy_2strjoin ("写入文件失败: ", file); : xy_2strjoin ("写入文件失败: ", file);
chsrc_error2 (msg); chsrc_error2 (msg);
exit (Exit_UserCause); exit (Exit_UserCause);
} }

View File

@ -7,7 +7,7 @@
* | * |
* Created On : <2024-12-11> * Created On : <2024-12-11>
* Major Revision : 1 * Major Revision : 1
* Last Modified : <2025-07-14> * Last Modified : <2025-07-26>
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
/** /**
@ -115,49 +115,34 @@ pl_python_uv_setsrc (char *option)
/** /**
* [[index]] default = true url = ".*" url = "source.url" * [[index]] default = true url = ".*" url = "source.url"
*/ */
char *update_source_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd); char *update_config_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_config_cmd = xy_str_gsub (update_config_cmd, "@f@", uv_config);
update_source_cmd = xy_str_gsub (update_source_cmd, "@url@", source.url); 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)) if (!xy_file_exist (uv_config))
{ {
/** /* 当 uv_config 不存在,直接写入文件 */
* uv_config chsrc_append_to_file (source_content, uv_config);
* run: append_source_cmd
*/
cmd = append_source_cmd;
} }
else 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_run (update_config_cmd, RunOpt_Default);
chsrc_note2 ("Windows 下暂不支持修改 uv.toml请手动修改配置文件");
} }
else else
{ {
/** chsrc_append_to_file (source_content, uv_config);
* 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);
} }
} }
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())
if(chsrc_in_standalone_mode())
{ {
chsrc_determine_chgtype (ChgType_Auto); chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source); chsrc_conclude (&source);