Skip to content

Fix clipboard settings being overwritten with empty values on exit - #5146

Merged
mc-worker merged 1 commit into
MidnightCommander:masterfrom
ChelpanovIlya:pr/fix-clipboard-overwrite
Aug 30, 2026
Merged

mc-worker merged 1 commit into
MidnightCommander:masterfrom
ChelpanovIlya:pr/fix-clipboard-overwrite

Conversation

@ChelpanovIlya

Copy link
Copy Markdown
Contributor

Proposed changes

When multiple mc instances are running, clipboard_store and clipboard_paste settings in the ini file get reset to empty strings.

Steps to reproduce:

  1. Set clipboard_store and clipboard_paste in ~/.config/mc/ini
  2. Open multiple mc instances in different terminals
  3. Close one mc instance — it saves the config with the correct values
  4. Close another mc instance that was started before the config was edited — it reads the OLD ini (before edits were made), loads empty strings for clipboard_store/clipboard_paste, and overwrites the config, erasing the user's settings

The root cause is that save_setup() unconditionally writes clipboard_store_path and clipboard_paste_path to the ini file, even when they are empty strings (which is the default when no clipboard utility is configured through mc's UI). This means any mc instance that started before the user edited the ini will overwrite the settings with empty values when it exits.

Fix: only write clipboard_store and clipboard_paste to the ini when the values are non-empty, preserving user-configured values.

Checklist

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@github-actions github-actions Bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Aug 28, 2026
@github-actions github-actions Bot added this to the Future Releases milestone Aug 28, 2026
…en with empty values on exit.

When multiple mc instances are running, clipboard_store and
clipboard_paste settings in the ini file get reset to empty strings.

Steps to reproduce:
1. Set clipboard_store and clipboard_paste in ~/.config/mc/ini
2. Open multiple mc instances in different terminals
3. Close one mc instance — it saves the config with the correct values
4. Close another mc instance that was started before the config was
   edited — it reads the OLD ini (before edits were made), loads empty
   strings for clipboard_store/clipboard_paste, and overwrites the
   config, erasing the user's settings

The root cause is that save_setup() unconditionally writes
clipboard_store_path and clipboard_paste_path to the ini file, even
when they are empty strings (which is the default when no clipboard
utility is configured through mc's UI). This means any mc instance
that started before the user edited the ini will overwrite the
settings with empty values when it exits.

Fix: only write clipboard_store and clipboard_paste to the ini when
the values are non-empty, preserving user-configured values.

Signed-off-by: ChelpanovIlya <ChelpanovIlya@users.noreply.github.com>
@aborodin
aborodin force-pushed the pr/fix-clipboard-overwrite branch from 63aa981 to 9942dbe Compare August 30, 2026 13:56
@mc-worker mc-worker added area: core Issues not related to a specific subsystem and removed needs triage Needs triage by maintainers labels Aug 30, 2026
@mc-worker mc-worker modified the milestones: Future Releases, 4.9.0 Aug 30, 2026
@mc-worker
mc-worker merged commit 77a4b52 into MidnightCommander:master Aug 30, 2026
4 checks passed
@ossilator

Copy link
Copy Markdown
Contributor

huh? i would have expected this to be an obvious reject: it's just the way mc's config works. adding exceptions for particular options is confusing, and just bad practice.

a proper generic solution would do a 3-way merge. that would require saving the originally read values (or at least tagging modified ones), and re-reading the file prior to writing it (at least if its timestamp changed). that's what proper frameworks like kde's kconfig do. glib has gsettings, but that's in gio, so i suppose mc isn't going to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

3 participants