-
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
Conversation
@@ -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 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.
because they might have these commented out or something like that.
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
@@ -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 comment
The 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 Config::save_with
all this will be resolved right? It will write over the existing config file with the new format, plus write out the port info into the new file without any of this extra code?
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.
Hmm Config::save_with
doesn't save the project config... but maybe it should?
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.
Hmm Config::save_with doesn't save the project config... but maybe it should?
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 comment
The 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.
This approach tries to read project config and see if there is a
[connection]
or[[ubs_device]]
section on it, this would mean that is an old config, and will parse the port_config out of it and write it toespflash_ports.toml
file (it will not remove the ports sections from the project file though)