Skip to content

MigrateConfig: stop duplicating options that have an empty value in the template - #950

Open
Cybis320 wants to merge 1 commit into
CroatianMeteorNetwork:prereleasefrom
Cybis320:fix-migrateconfig-empty-value-duplicates
Open

MigrateConfig: stop duplicating options that have an empty value in the template#950
Cybis320 wants to merge 1 commit into
CroatianMeteorNetwork:prereleasefrom
Cybis320:fix-migrateconfig-empty-value-duplicates

Conversation

@Cybis320

Copy link
Copy Markdown
Contributor

Problem

MigrateConfig writes a duplicate entry for any option whose template value is empty, producing a .config that RMS cannot read:

[Build]

; Compiler arguments for cython
rpi_weave: -O3 -mfpu=neon -funsafe-loop-optimizations -ftree-loop-if-convert-stores
linux_pc_weave: -O3
win_pc_weave:

; The following options were preserved but are not in the template
win_pc_weave: -Wall

configparser then raises DuplicateOptionError and RMS crashes on startup.

Two options in the template have empty values, and both are affected:

  • time_server: (.config:62)
  • win_pc_weave: (.config:392)

Cause

Attribute lines were parsed with re.split(": ", l), which requires a colon followed by a space. Lines with an empty value do not match, so in the template merge loop they took the cnt != 2 branch: the template line was written out verbatim and the key was never removed from attributes_dict. It then fell through to the "unrecognized attributes preserved" step, where the option is valid per ConfigReader.py, so it was appended a second time.

The crash only shows up when the user's config has a non-empty value for one of these options, which is why it went unnoticed.

Fix

  • New parseAttributeLine() helper using ^([^:]+?)\s*:\s*(.*)$, replacing both re.split(": ", ...) sites. It handles empty values and makes the space after the colon optional — linux_pc_weave:-O2 was previously dropped silently, losing the user's setting.
  • Preserved empty values are written without a trailing space (rpi_weave:, not rpi_weave: ).
  • Added a duplicate guard in the preserve step: options already present in the new config are skipped (matched case-insensitively, as configparser does). This backstops the same crash from any other parse gap or case mismatch.

Testing

  • Repro before the fix: duplicate win_pc_weave/time_server, DuplicateOptionError. After: values kept in place, config parses, win_pc_weave = '-Wall'.
  • Recovery: running the fixed migrator over an already-corrupted config heals it — it warns duplicate value for win_pc_weave, assuming last value, keeps -Wall, and emits a single valid entry. Affected stations can just re-run python -m Utils.MigrateConfig -u.
  • Identity test (repo .config migrated against itself) is byte-identical apart from the added ; Reformated by footer — no drift across the other 190 attributes.
  • Edge cases covered: user-cleared value, no space after the colon, and values containing colons (device: rtsp://...).

🤖 Generated with Claude Code

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.

1 participant