Skip to content

Commit 61944e0

Browse files
committed
Don't use printf in uv
1 parent ff3e80c commit 61944e0

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

src/framework/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ chsrc_append_to_file (const char *str, const char *filename)
16061606
if (ret != 1)
16071607
{
16081608
char *msg = ENGLISH ? xy_2strjoin ("Write failed to ", file)
1609-
: xy_2strjoin ("写入文件失败: ", file);
1609+
: xy_2strjoin ("写入文件失败: ", file);
16101610
chsrc_error2 (msg);
16111611
exit (Exit_UserCause);
16121612
}

src/recipe/lang/Python/uv.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* |
88
* Created On : <2024-12-11>
99
* Major Revision : 1
10-
* Last Modified : <2025-07-14>
10+
* Last Modified : <2025-07-26>
1111
* ------------------------------------------------------------*/
1212

1313
/**
@@ -115,49 +115,34 @@ pl_python_uv_setsrc (char *option)
115115
/**
116116
* 将 [[index]] 到 default = true 之间的 url = ".*" 替换为 url = "source.url"
117117
*/
118-
char *update_source_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd);
119-
update_source_cmd = xy_str_gsub (update_source_cmd, "@f@", uv_config);
120-
update_source_cmd = xy_str_gsub (update_source_cmd, "@url@", source.url);
118+
char *update_config_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd);
119+
update_config_cmd = xy_str_gsub (update_config_cmd, "@f@", uv_config);
120+
update_config_cmd = xy_str_gsub (update_config_cmd, "@url@", source.url);
121121

122-
char *append_source_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
122+
char *append_config_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
123123

124-
char *cmd = NULL;
125124
if (!xy_file_exist (uv_config))
126125
{
127-
/**
128-
* uv_config 不存在,追加到新文件末尾
129-
* run: append_source_cmd
130-
*/
131-
cmd = append_source_cmd;
126+
/* 当 uv_config 不存在,直接写入文件 */
127+
chsrc_append_to_file (source_content, uv_config);
132128
}
133129
else
134130
{
135-
if (xy_on_windows)
131+
/* 当 uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾 */
132+
char *cmd = xy_str_gsub (RAWSTR_pl_python_test_uv_if_set_source, "@f@", uv_config);
133+
chsrc_ensure_program ("grep");
134+
int status = system (cmd);
135+
if (0==status)
136136
{
137-
/* TODO: Windows 下替换源暂不支持 */
138-
chsrc_note2 ("Windows 下暂不支持修改 uv.toml,请手动修改配置文件");
137+
chsrc_run (update_config_cmd, RunOpt_Default);
139138
}
140139
else
141140
{
142-
/**
143-
* uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾
144-
*/
145-
cmd = xy_str_gsub (RAWSTR_pl_python_final_uv_cmd, "@f@", uv_config);
146-
cmd = xy_str_gsub (cmd, "@ucmd@", update_source_cmd);
147-
cmd = xy_str_gsub (cmd, "@acmd@", append_source_cmd);
141+
chsrc_append_to_file (source_content, uv_config);
148142
}
149143
}
150-
if (NULL==cmd)
151-
{
152-
chsrc_note2 (xy_strjoin (4, "请手动为 ", uv_config, "添加或修改 [[index]] 配置项的 url = ", source.url));
153-
}
154-
else
155-
{
156-
chsrc_run (cmd, RunOpt_Default);
157-
}
158144

159-
160-
if(chsrc_in_standalone_mode())
145+
if (chsrc_in_standalone_mode())
161146
{
162147
chsrc_determine_chgtype (ChgType_Auto);
163148
chsrc_conclude (&source);

0 commit comments

Comments
 (0)