Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/xy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 返回一个路径的父目录名
Expand Down
1 change: 1 addition & 0 deletions src/chsrc-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 22 additions & 9 deletions src/recipe/lang/Rust/Cargo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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, "'", "\"");

Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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);
}
Expand Down