diff --git a/src/framework/core.c b/src/framework/core.c index 8f4a9c0..6e67ad6 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -51,6 +51,8 @@ TargetGroupMode = }; bool chsrc_in_target_group_mode() {return TargetGroupMode.in;} +// 并非作为 follower target,而是自身作为一个独立的 target 执行 +bool chsrc_in_standalone_mode() {return !TargetGroupMode.in;} void chsrc_set_target_group_mode(){TargetGroupMode.in = true;} @@ -855,13 +857,14 @@ source_has_empty_url (Source_t *source) * 3. 用户什么都没指定, 即 chsrc set * 4. 用户正在重置源, 即 chsrc reset * - * 如果处于 Target Group 模式下,leader target 可能会指定一个源,因此还有一种情况: + * 如果处于 Target Group 模式下,leader target 已经测速过了,follower target 不能再次测速,而是直接选择 leader 测过的结果 * - * 5. leader target 指定了某个源 + * 5. leader target 测速出来的某个源 * * @dependency 已存在的局部变量 @var:option */ -#define chsrc_yield_for_the_source(for_what) \ +#define chsrc_yield_source(for_what) \ + Source_t source; \ if (chsrc_in_target_group_mode() && TargetGroupMode.leader_selected_index==-1) \ { \ TargetGroupMode.leader_selected_index = use_specific_mirror_or_auto_select (option, for_what); \ @@ -882,9 +885,6 @@ source_has_empty_url (Source_t *source) source = for_what##_sources[__index]; \ } -#define chsrc_yield_source(for_what) \ - Source_t source; \ - chsrc_yield_for_the_source(for_what) diff --git a/src/recipe/lang/Node.js/Yarn.c b/src/recipe/lang/Node.js/Yarn.c index b0c5dcb..c86b46f 100644 --- a/src/recipe/lang/Node.js/Yarn.c +++ b/src/recipe/lang/Node.js/Yarn.c @@ -5,7 +5,7 @@ * Contributors : Mr. Will * Created On : <2023-09-09> * Major Reviison : 3 - * Last Modified : <2024-09-13> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ static double @@ -40,9 +40,8 @@ pl_nodejs_yarn_getsrc (char *option) void pl_nodejs_yarn_setsrc (char *option) { - Source_t source; - chsrc_yield_for_the_source (pl_nodejs); - if (!chsrc_in_target_group_mode()) + chsrc_yield_source (pl_nodejs); + if (chsrc_in_standalone_mode()) chsrc_confirm_source; char *cmd = NULL; @@ -71,7 +70,7 @@ pl_nodejs_yarn_setsrc (char *option) chsrc_run (cmd, RunOpt_No_Last_New_Line); } - if (!chsrc_in_target_group_mode()) + if (chsrc_in_standalone_mode()) { chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/src/recipe/lang/Node.js/npm.c b/src/recipe/lang/Node.js/npm.c index 6f28fa7..5af7c9f 100644 --- a/src/recipe/lang/Node.js/npm.c +++ b/src/recipe/lang/Node.js/npm.c @@ -5,7 +5,7 @@ * Contributors : Mr. Will * Created On : <2023-08-30> * Major Revision : 2 - * Last Modified : <2024-09-13> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ /** @@ -26,9 +26,8 @@ pl_nodejs_npm_getsrc (char *option) void pl_nodejs_npm_setsrc (char *option) { - Source_t source; - chsrc_yield_for_the_source (pl_nodejs); - if (!chsrc_in_target_group_mode()) + chsrc_yield_source (pl_nodejs); + if (chsrc_in_standalone_mode()) chsrc_confirm_source; char *cmd = NULL; @@ -40,7 +39,7 @@ pl_nodejs_npm_setsrc (char *option) chsrc_run (cmd, RunOpt_No_Last_New_Line); - if (!chsrc_in_target_group_mode()) + if (chsrc_in_standalone_mode()) { chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/src/recipe/lang/Node.js/pnpm.c b/src/recipe/lang/Node.js/pnpm.c index 9d6315b..604efe8 100644 --- a/src/recipe/lang/Node.js/pnpm.c +++ b/src/recipe/lang/Node.js/pnpm.c @@ -5,7 +5,7 @@ * Contributors : Nul None * Created On : <2024-04-18> * Major Revision : 2 - * Last Modified : <2024-09-13> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ /** @@ -27,9 +27,8 @@ pl_nodejs_pnpm_getsrc (char *option) void pl_nodejs_pnpm_setsrc (char *option) { - Source_t source; - chsrc_yield_for_the_source (pl_nodejs); - if (!chsrc_in_target_group_mode()) + chsrc_yield_source (pl_nodejs); + if (chsrc_in_standalone_mode()) chsrc_confirm_source; char *cmd = NULL; @@ -41,7 +40,7 @@ pl_nodejs_pnpm_setsrc (char *option) chsrc_run (cmd, RunOpt_No_Last_New_Line); - if (!chsrc_in_target_group_mode()) + if (chsrc_in_standalone_mode()) { chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/src/recipe/lang/Python/PDM.c b/src/recipe/lang/Python/PDM.c index 326f7c3..d2ef39e 100644 --- a/src/recipe/lang/Python/PDM.c +++ b/src/recipe/lang/Python/PDM.c @@ -4,7 +4,7 @@ * File Authors : Aoran Zeng * Contributors : Nul None * Created On : <2024-06-05> - * Last Modified : <2024-09-14> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ /** @@ -28,9 +28,8 @@ pl_python_pdm_getsrc (char *option) void pl_python_pdm_setsrc (char *option) { - Source_t source; - chsrc_yield_for_the_source (pl_python); - if (!chsrc_in_target_group_mode()) + chsrc_yield_source (pl_python); + if (chsrc_in_standalone_mode()) chsrc_confirm_source; char *cmd = NULL; @@ -42,7 +41,7 @@ pl_python_pdm_setsrc (char *option) chsrc_run (cmd, RunOpt_No_Last_New_Line); - if (!chsrc_in_target_group_mode()) + if (chsrc_in_standalone_mode()) { chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/src/recipe/lang/Python/Poetry.c b/src/recipe/lang/Python/Poetry.c index fe9cacb..68435b2 100644 --- a/src/recipe/lang/Python/Poetry.c +++ b/src/recipe/lang/Python/Poetry.c @@ -4,7 +4,7 @@ * File Authors : Aoran Zeng * Contributors : Nil Null * Created On : <2024-08-08> - * Last Modified : <2024-09-14> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ // @note Poetry 默认使用项目级换源 @@ -27,9 +27,8 @@ pl_python_poetry_getsrc (char *option) void pl_python_poetry_setsrc (char *option) { - Source_t source; - chsrc_yield_for_the_source (pl_python); - if (!chsrc_in_target_group_mode()) + chsrc_yield_source (pl_python); + if (chsrc_in_standalone_mode()) chsrc_confirm_source; char *cmd = NULL; @@ -40,7 +39,7 @@ pl_python_poetry_setsrc (char *option) cmd = xy_2strjoin ("poetry source add my_mirror ", source.url); chsrc_run (cmd, RunOpt_No_Last_New_Line); - if (!chsrc_in_target_group_mode()) + if (chsrc_in_standalone_mode()) { chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/src/recipe/lang/Python/Rye.c b/src/recipe/lang/Python/Rye.c index 4b295ac..b8a0dfe 100644 --- a/src/recipe/lang/Python/Rye.c +++ b/src/recipe/lang/Python/Rye.c @@ -4,7 +4,7 @@ * File Authors : Aoran Zeng * Contributors : Nul None * Created On : <2024-12-06> - * Last Modified : <2024-12-06> + * Last Modified : <2025-07-11> * * 由于Rye已经有后继uv了,所以我们不把该管理器纳入Python group中 * ------------------------------------------------------------*/ @@ -38,6 +38,7 @@ pl_python_rye_getsrc (char *option) void pl_python_rye_setsrc (char *option) { + /* 并不在 Python group 中,所以不考虑 target group 情况 */ chsrc_yield_source_and_confirm (pl_python); const char *file = xy_strjoin (7, diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index 052c585..d3a25ac 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -4,7 +4,7 @@ * File Authors : Aoran Zeng * Contributors : Nul None * Created On : <2023-09-03> - * Last Modified : <2024-09-14> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ /** @@ -38,9 +38,8 @@ pl_python_pip_setsrc (char *option) return; } - Source_t source; - chsrc_yield_for_the_source (pl_python); - if (!chsrc_in_target_group_mode()) + chsrc_yield_source (pl_python); + if (chsrc_in_standalone_mode()) chsrc_confirm_source; char *py_prog_name = NULL; @@ -52,7 +51,7 @@ pl_python_pip_setsrc (char *option) char *cmd = xy_2strjoin (py_prog_name, xy_2strjoin (" -m pip config --user set global.index-url ", source.url)); chsrc_run (cmd, RunOpt_No_Last_New_Line); - if (!chsrc_in_target_group_mode()) + if (chsrc_in_standalone_mode()) { chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); diff --git a/src/recipe/lang/Python/uv.c b/src/recipe/lang/Python/uv.c index 383afdc..d61cb72 100644 --- a/src/recipe/lang/Python/uv.c +++ b/src/recipe/lang/Python/uv.c @@ -6,7 +6,7 @@ * | Aoran Zeng * | * Created On : <2024-12-11> - * Last Modified : <2025-06-02> + * Last Modified : <2025-07-11> * ------------------------------------------------------------*/ /** @@ -94,10 +94,11 @@ pl_python_uv_getsrc (char *option) void pl_python_uv_setsrc (char *option) { - chsrc_ensure_program("uv"); + chsrc_ensure_program ("uv"); - Source_t source; - chsrc_yield_for_the_source (pl_python); + chsrc_yield_source (pl_python); + if (chsrc_in_standalone_mode()) + chsrc_confirm_source; char *uv_config = pl_python_find_uv_config (true); if (NULL==uv_config) @@ -168,8 +169,12 @@ pl_python_uv_setsrc (char *option) chsrc_run (cmd, RunOpt_Default); } - chsrc_determine_chgtype (ChgType_Auto); - chsrc_conclude (&source); + + if(chsrc_in_standalone_mode()) + { + chsrc_determine_chgtype (ChgType_Auto); + chsrc_conclude (&source); + } }