-
Notifications
You must be signed in to change notification settings - Fork 140
Migrate old config #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Migrate old config #883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,26 @@ impl Config { | |
|
||
let mut port_config = if let Ok(data) = read_to_string(&port_config_file) { | ||
toml::from_str(&data).into_diagnostic()? | ||
} else if let Ok(data) = read_to_string(&project_config_file) { | ||
if data.contains("[connection]") || data.contains("[[usb_device]]") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we decide that we need to do the migration, we also need to remove the keys from the project config, once the ports file has been succesfully saved. I'm pretty sure if we just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not sure if it should, the only scenario when we write config is to store port config when the users selects a port and wants to save it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okay, if it doesn't make sense to save the project config we can keep the special case save here then. |
||
debug!( | ||
"espflash@3 configuration detected. Migrating port config to port_config_file: {:#?}", | ||
&port_config_file | ||
); | ||
let port_config = toml::from_str(&data).into_diagnostic()?; | ||
let serialized = toml::to_string(&port_config) | ||
.into_diagnostic() | ||
.wrap_err("Failed to serialize config")?; | ||
create_dir_all(port_config_file.parent().unwrap()) | ||
.into_diagnostic() | ||
.wrap_err("Failed to create config directory")?; | ||
write(&port_config_file, serialized) | ||
.into_diagnostic() | ||
.wrap_err("Failed to write config")?; | ||
port_config | ||
} else { | ||
PortConfig::default() | ||
} | ||
} else { | ||
PortConfig::default() | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this as an idea is good, but I think we should at least parse the toml because they might have these commented out or something like that.
We can do this in two ways, we "recreate" the old config struct to try and parse it, or we use https://docs.rs/toml/0.8.23/toml/#parsing-toml to just parse the file as a whole and we can just inspect the keys before making a decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they are commented out, then
let port_config = toml::from_str(&data).into_diagnostic()?;
would not read it. But maybe its better your approach