@@ -78,12 +78,33 @@ pl_rust_cargo_note_get_src_mirror (char *url, bool sparse)
7878 say (xy_2strcat (url , sparse ? " (sparse)" : "" ));
7979}
8080
81+ static char *
82+ pl_rust_cargo_config_file (void )
83+ {
84+ char * file = xy_normalize_path ("~/.cargo/config.toml" );
85+ char * cargo_home = getenv ("CARGO_HOME" );
86+ if (cargo_home && * cargo_home )
87+ {
88+ char * dir = xy_normalize_path (cargo_home );
89+ if (!xy_str_end_with (dir , "/" ) && !xy_str_end_with (dir , "\\" ))
90+ {
91+ char * tmp = xy .on_windows ? xy_2strcat (dir , "\\" ) : xy_2strcat (dir , "/" );
92+ free (dir );
93+ dir = tmp ;
94+ }
95+ file = xy_2strcat (dir , "config.toml" );
96+ free (dir );
97+ }
98+ return file ;
99+ }
100+
81101void
82102pl_rust_cargo_getsrc (char * option )
83103{
84- char * cargo_config_file = xy_normalize_path ( "~/.cargo/config.toml" );
104+ char * cargo_config_file = pl_rust_cargo_config_file ( );
85105
86106 char * raw_content = xy_file_read (cargo_config_file );
107+ free (cargo_config_file );
87108 char * formatted_content = xy_str_gsub (raw_content , " " , "" );
88109 formatted_content = xy_str_gsub (formatted_content , "'" , "\"" );
89110
@@ -136,12 +157,7 @@ pl_rust_cargo_setsrc (char *option)
136157 chsrc_use_this_source (pl_rust_cargo );
137158
138159 char * default_content = RAWSTR_pl_rust_cargo_config ;
139- char * cargo_config_dir = "~/.cargo/" ;
140- char * cargo_config_file = xy_2strcat (cargo_config_dir , "config.toml" );
141-
142- chsrc_ensure_dir (cargo_config_dir );
143-
144- cargo_config_file = xy_normalize_path (cargo_config_file );
160+ char * cargo_config_file = pl_rust_cargo_config_file ();
145161
146162 if (xy_file_exist (cargo_config_file ))
147163 {
@@ -188,6 +204,7 @@ pl_rust_cargo_setsrc (char *option)
188204 goto finish ;
189205
190206finish :
207+ free (cargo_config_file );
191208 chsrc_determine_chgtype (ChgType_Auto );
192209 chsrc_conclude (& source );
193210}
0 commit comments