Skip to content

Section-marker awk state machine duplicated 4-5 times in lib_file.sh #288

Description

@codeforester

Summary

lib/bash/file/lib_file.sh reimplements the same "walk lines, track in_section, match START_M/END_M" awk logic in near-identical inline blocks in up to five places.

Details

  • :143-172 (__base_bash_libs_file_section_markers_ordered__)
  • :276-298 (base_file_section_needs_update)
  • :438-453 (inside base_file_update_file_section)
  • :486-506 (removal variant)
  • :522-548 (replace variant)

base_file_section_needs_update already duplicates its own extraction logic almost verbatim against base_file_update_file_section.

Impact

A future correctness fix (e.g. CRLF handling, marker-matching edge cases) has to be applied in up to five places, and is easy to miss in one of them.

Suggested fix

Factor the shared awk program(s) into one or two parameterized helpers (e.g. a mode=extract|check|remove|replace argument) instead of five inline copies.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or product improvement

Type

No type

Projects

Status
Triage

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions