Skip to content

Improving block file change detection#5071

Open
jtyr wants to merge 1 commit intoMidnightCommander:masterfrom
jtyr:jtyr-block-file
Open

Improving block file change detection#5071
jtyr wants to merge 1 commit intoMidnightCommander:masterfrom
jtyr:jtyr-block-file

Conversation

@jtyr
Copy link

@jtyr jtyr commented Mar 15, 2026

Summary

Fixes two related issues with editor macro scripts and the block file.

Problem 1: Block file not saved before macro execution

edit_block_process_cmd() runs a numbered macro script that may reference %b (the block file). However, the selected block is not written to the block file before the script runs, so %b points to a stale or nonexistent file.

The fix is to save the selected block to EDIT_HOME_BLOCK_FILE at the start of edit_block_process_cmd(), before calling edit_user_menu().

Problem 2: Block file modification missed due to second-precision timestamps

edit_user_menu() detects whether a macro script modified the block file by comparing st_size and st_mtime before and after execution. Scripts that rearrange bytes without changing file size (e.g., word-wrap replacing spaces with newlines) and complete within the same second produce identical st_size and st_mtime, causing a false negative - the editor does not reload the modified block.

The fix is to use nanosecond-precision st_mtim (via HAVE_STRUCT_STAT_ST_MTIM, already detected by configure) instead of second-precision st_mtime. Falls back to st_mtime on platforms without nanosecond support.

Test plan

  • Select a block, run a macro that transforms it (e.g., sort, word-wrap) - the result should be inserted back into the editor
  • Run a macro that produces identical file size but different content - the change should be detected
  • Build on a platform without st_mtim - should compile and fall back to second-precision comparison

Signed-off-by: Jiri Tyr <jiri.tyr@gmail.com>
@github-actions github-actions bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Mar 15, 2026
@github-actions github-actions bot added this to the Future Releases milestone Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs triage Needs triage by maintainers prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

1 participant