@@ -10,12 +10,12 @@ pl_rust_cargo_prelude (void)
1010 chef_prep_this (pl_rust_cargo , gsr );
1111
1212 chef_set_created_on (this , "2023-08-30" );
13- chef_set_last_updated (this , "2025-07-22 " );
13+ chef_set_last_updated (this , "2025-09-13 " );
1414 chef_set_sources_last_updated (this , "2025-06-18" );
1515
1616 chef_set_chef (this , NULL );
1717 chef_set_cooks (this , 1 , "@ccmywish" );
18- chef_set_sauciers (this , 1 , "@Mikachu2333" );
18+ chef_set_sauciers (this , 2 , "@Mikachu2333" , "@happy-game " );
1919
2020 chef_allow_local_mode (this , PartiallyCan , "可以基于本项目换源吗?请帮助确认" , "Can it change sources based on this project? Please help confirm" );
2121 chef_forbid_english (this );
@@ -62,14 +62,58 @@ pl_rust_cargo_getsrc (char *option)
6262void
6363pl_rust_cargo_setsrc (char * option )
6464{
65+ chsrc_ensure_program ("cargo" );
66+
6567 chsrc_use_this_source (pl_rust_cargo );
6668
67- char * content = RAWSTR_pl_rust_cargo_config ;
69+ char * cargo_config_dir = "~/.cargo/" ;
70+ char * cargo_config_file = xy_2strcat (cargo_config_dir , "config.toml" );
71+
72+ chsrc_ensure_dir (cargo_config_dir );
73+
74+ cargo_config_file = xy_normalize_path (cargo_config_file );
75+
76+ if (xy_file_exist (cargo_config_file ))
77+ {
78+ chsrc_backup (cargo_config_file );
79+ }
6880
81+ char * content = RAWSTR_pl_rust_cargo_config ;
6982 content = xy_str_gsub (content , "@url@" , source .url );
7083
71- chsrc_note2 (xy_strcat (3 , "请手动写入以下内容到 " , xy_normalize_path ("~/.cargo/config.toml" ), " 文件中:" ));
72- println (content );
84+ if (xy_file_exist (cargo_config_file ))
85+ {
86+ char * check_cmd = xy_str_gsub (RAWSTR_pl_rust_cargo_check_config , "@f@" , cargo_config_file );
87+ chsrc_ensure_program ("grep" );
88+ int status = chsrc_run_directly (check_cmd );
89+
90+ if (0 == status )
91+ {
92+ #if defined(XY_Build_On_macOS ) || defined(XY_Build_On_BSD )
93+ char * sed_cmd = "sed -i '' " ;
94+ #else
95+ char * sed_cmd = "sed -i " ;
96+ #endif
97+
98+ char * update_cmd = xy_str_gsub (RAWSTR_pl_rust_cargo_update_replace_with , "@sed@" , sed_cmd );
99+ update_cmd = xy_str_gsub (update_cmd , "@f@" , cargo_config_file );
100+ chsrc_run (update_cmd , RunOpt_Default );
101+
102+ update_cmd = xy_str_gsub (RAWSTR_pl_rust_cargo_update_registry , "@sed@" , sed_cmd );
103+ update_cmd = xy_str_gsub (update_cmd , "@f@" , cargo_config_file );
104+ update_cmd = xy_str_gsub (update_cmd , "@url@" , source .url );
105+ chsrc_run (update_cmd , RunOpt_Default );
106+ }
107+ else
108+ {
109+ chsrc_append_to_file ("\n" , cargo_config_file );
110+ chsrc_append_to_file (content , cargo_config_file );
111+ }
112+ }
113+ else
114+ {
115+ chsrc_append_to_file (content , cargo_config_file );
116+ }
73117
74118 chsrc_determine_chgtype (ChgType_Auto );
75119 chsrc_conclude (& source );
0 commit comments