From 1851b5e943ca7e577237c066b91ceea5ac42c589 Mon Sep 17 00:00:00 2001 From: AnonTokio Date: Sat, 21 Mar 2026 21:02:40 +0800 Subject: [PATCH 1/2] feat(path): add path join --- lib/xy.h | 24 ++++++++++++++++++++++++ src/chsrc-main.c | 1 + 2 files changed, 25 insertions(+) diff --git a/lib/xy.h b/lib/xy.h index 6475006b..d01e8d20 100644 --- a/lib/xy.h +++ b/lib/xy.h @@ -1370,6 +1370,30 @@ xy_normalize_path (const char *path) return new; } +/** + * @flavor Ruby: Pathname#join + * + * @memory SAFE + * return caller-free + */ +static char * +xy_path_join (const char *path1, const char *path2) +{ + char *sep = xy.on_windows ? "\\" : "/"; + char *path1_norm = xy_normalize_path (path1); + char *path2_norm = xy_normalize_path (path2); + if (!xy_str_end_with (path1_norm, sep)) + { + char *tmp = xy_2strcat (path1_norm, sep); + free (path1_norm); + path1_norm = tmp; + } + char *path_joined = xy_2strcat (path1_norm, path2_norm); + free (path1_norm); + free (path2_norm); + return path_joined; +} + /** * @brief 返回一个路径的父目录名 diff --git a/src/chsrc-main.c b/src/chsrc-main.c index 83ec81da..0af8f1a1 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -72,6 +72,7 @@ chsrc_register_contributors () chef_register_contributor ("@Mikachu2333", "Mikachu2333", "mikachu.23333@zohomail.com", NULL); chef_register_contributor ("@techoc", "Rui Yang", "techoc@foxmail.com", NULL); chef_register_contributor ("@BingChunMoLi", "BingChunMoLi", "bingchunmoli@bingchunmoli.com", NULL); + chef_register_contributor ("@AnonTokio", "Anon Tokio", "anontokio@163.com", NULL); // 该 ID 为 Gitee ID chef_register_contributor ("@hezonglun", "HeZongLun", "hezonglun123456@outlook.com", NULL); chef_register_contributor ("@Young-Lord", "LY", "ly-niko@qq.com", NULL); From 7748e7bd1cc166f6d40773c277936b55806d31c8 Mon Sep 17 00:00:00 2001 From: AnonTokio Date: Fri, 20 Mar 2026 22:04:40 +0800 Subject: [PATCH 2/2] feat(cargo): Use the CARGO_HOME environment variable to locate the configuration file. --- src/recipe/lang/Rust/Cargo.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/recipe/lang/Rust/Cargo.c b/src/recipe/lang/Rust/Cargo.c index 98cf515a..2f102c88 100644 --- a/src/recipe/lang/Rust/Cargo.c +++ b/src/recipe/lang/Rust/Cargo.c @@ -11,11 +11,11 @@ pl_rust_cargo_prelude (void) chef_set_recipe_created_on (this, "2023-08-30"); chef_set_recipe_last_updated (this, "2025-12-31"); - chef_set_sources_last_updated (this, "2026-01-21"); + chef_set_sources_last_updated (this, "2026-03-21"); chef_set_chef (this, NULL); chef_set_cooks (this, 2, "@Mikachu2333", "@ccmywish"); - chef_set_sauciers (this, 1, "@happy-game"); + chef_set_sauciers (this, 2, "@happy-game", "@AnonTokio"); chef_set_scope_cap (this, ProjectScope, ScopeCap_Able_But_Not_Implemented); chef_set_scope_cap (this, UserScope, ScopeCap_Able_And_Implemented); @@ -78,12 +78,29 @@ pl_rust_cargo_note_get_src_mirror (char *url, bool sparse) say (xy_2strcat (url, sparse ? " (sparse)" : "")); } +static char * +pl_rust_cargo_config_file (void) +{ + char *file = NULL; + char *cargo_home = getenv ("CARGO_HOME"); + if (cargo_home && *cargo_home) + { + file = xy_path_join (cargo_home, "config.toml"); + } + else + { + file = xy_normalize_path ("~/.cargo/config.toml"); + } + return file; +} + void pl_rust_cargo_getsrc (char *option) { - char *cargo_config_file = xy_normalize_path ("~/.cargo/config.toml"); + char *cargo_config_file = pl_rust_cargo_config_file (); char *raw_content = xy_file_read (cargo_config_file); + free (cargo_config_file); char *formatted_content = xy_str_gsub (raw_content, " ", ""); formatted_content = xy_str_gsub (formatted_content, "'", "\""); @@ -136,12 +153,7 @@ pl_rust_cargo_setsrc (char *option) chsrc_use_this_source (pl_rust_cargo); char *default_content = RAWSTR_pl_rust_cargo_config; - char *cargo_config_dir = "~/.cargo/"; - char *cargo_config_file = xy_2strcat (cargo_config_dir, "config.toml"); - - chsrc_ensure_dir (cargo_config_dir); - - cargo_config_file = xy_normalize_path (cargo_config_file); + char *cargo_config_file = pl_rust_cargo_config_file (); if (xy_file_exist (cargo_config_file)) { @@ -188,6 +200,7 @@ pl_rust_cargo_setsrc (char *option) goto finish; finish: + free (cargo_config_file); chsrc_determine_chgtype (ChgType_Auto); chsrc_conclude (&source); }