File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -155,14 +155,15 @@ impl AppSettings {
155155 config_dir : & Path ,
156156 migration_file : & Path ,
157157 ) -> anyhow:: Result < ( AppSettingsValue , bool ) > {
158+ // Apply any pending config migrations before reading the settings
159+ // file.
160+ apply_config_migrations ( config_dir, migration_file) ?;
161+
158162 let settings_path = config_dir. join ( "settings.json" ) ;
159163 let is_found = settings_path. exists ( ) ;
160164
161- // Apply any pending config migrations before reading the settings
162- // file. If the file does not exist, initialize a default.
163- if is_found {
164- apply_config_migrations ( config_dir, migration_file) ?;
165- } else {
165+ // If the file does not exist, initialize a default.
166+ if !is_found {
166167 Self :: create_default ( config_dir) ?;
167168 }
168169
Original file line number Diff line number Diff line change @@ -33,7 +33,10 @@ impl ConfigMigration {
3333 }
3434}
3535
36- /// Migrates config files to the latest version.
36+ /// Migrates existing config files to the latest version.
37+ ///
38+ /// Any migrations that have already been applied will be skipped. If
39+ /// no migrations are needed, the function will no-op.
3740pub fn apply_config_migrations (
3841 config_dir : & Path ,
3942 migration_file : & Path ,
@@ -74,6 +77,11 @@ pub fn apply_config_migrations(
7477fn migrate_startup_config ( config_dir : & Path ) -> anyhow:: Result < ( ) > {
7578 let settings_path = config_dir. join ( "settings.json" ) ;
7679
80+ // Skip if the settings file does not exist.
81+ if !settings_path. exists ( ) {
82+ return Ok ( ( ) ) ;
83+ }
84+
7785 let settings_json =
7886 read_and_parse_json :: < serde_json:: Value > ( & settings_path)
7987 . context ( "Failed to parse settings.json" ) ?;
You can’t perform that action at this time.
0 commit comments