@@ -52,8 +52,6 @@ pub fn parse_toml_value_or_bare_string(value_str: &str) -> toml_edit::Value {
5252pub enum ConfigEnvError {
5353 #[ error( "Both {0} and {1} exist. Please consolidate your configs in one of them." ) ]
5454 AmbiguousSource ( PathBuf , PathBuf ) ,
55- #[ error( transparent) ]
56- CreateFile ( std:: io:: Error ) ,
5755}
5856
5957/// Configuration variable with its source information.
@@ -164,18 +162,6 @@ fn create_dir_all(path: &Path) -> std::io::Result<()> {
164162 dir. create ( path)
165163}
166164
167- fn create_config_file ( path : & Path ) -> std:: io:: Result < std:: fs:: File > {
168- if let Some ( parent) = path. parent ( ) {
169- create_dir_all ( parent) ?;
170- }
171- // TODO: Use File::create_new once stabilized.
172- std:: fs:: OpenOptions :: new ( )
173- . read ( true )
174- . write ( true )
175- . create_new ( true )
176- . open ( path)
177- }
178-
179165// The struct exists so that we can mock certain global values in unit tests.
180166#[ derive( Clone , Default , Debug ) ]
181167struct UnresolvedConfigEnv {
@@ -246,27 +232,6 @@ impl ConfigEnv {
246232 }
247233 }
248234
249- /// Returns a path to the user-specific config file.
250- ///
251- /// If no config file is found, tries to guess a reasonable new location for
252- /// it. If a path to a new config file is returned, the parent directory may
253- /// be created as a result of this call.
254- pub fn new_user_config_path ( & self ) -> Result < Option < & Path > , ConfigEnvError > {
255- match & self . user_config_path {
256- ConfigPath :: Existing ( path) => Ok ( Some ( path) ) ,
257- ConfigPath :: New ( path) => {
258- // TODO: Maybe we shouldn't create new file here. Not all
259- // callers need an empty file. "jj config set" doesn't have
260- // to create an empty file to be overwritten. Since it's unclear
261- // who and when to update ConfigPath::New(_) to ::Existing(_),
262- // it's probably better to not cache the path existence.
263- create_config_file ( path) . map_err ( ConfigEnvError :: CreateFile ) ?;
264- Ok ( Some ( path) )
265- }
266- ConfigPath :: Unavailable => Ok ( None ) ,
267- }
268- }
269-
270235 /// Returns user configuration files for modification. Instantiates one if
271236 /// `config` has no user configuration layers.
272237 ///
@@ -1116,19 +1081,10 @@ mod tests {
11161081 let env = self
11171082 . resolve ( tmp. path ( ) )
11181083 . map_err ( |e| anyhow ! ( "new_config_path: {e}" ) ) ?;
1119- let got = env
1120- . new_user_config_path ( )
1121- . map_err ( |e| anyhow ! ( "new_config_path: {e}" ) ) ?;
1084+ let got = env. user_config_path ( ) ;
11221085 if got != want. as_deref ( ) {
11231086 return Err ( anyhow ! ( "new_config_path: got {got:?}, want {want:?}" ) ) ;
11241087 }
1125- if let Some ( path) = got {
1126- if !Path :: new ( & path) . is_file ( ) {
1127- return Err ( anyhow ! (
1128- "new_config_path returned {path:?} which is not a file"
1129- ) ) ;
1130- }
1131- }
11321088 Ok ( ( ) )
11331089 }
11341090 }
0 commit comments