Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SergioGasquez
Copy link
Member

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 to espflash_ports.toml file (it will not remove the ports sections from the project file though)

@SergioGasquez SergioGasquez linked an issue Jun 13, 2025 that may be closed by this pull request
@@ -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]]") {
Copy link
Member

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.

Copy link
Member Author

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]]") {
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

espflash split config migration
2 participants