Skip to content

file: expose marked-section inspection for profile cleanup #101

Description

@codeforester

Context

Follow-up from basefoundry/base#1380. That PR made basectl update-profile --remove reversible and safe, and it already uses update_file_section -r from base-bash-libs for the actual marker-delimited removal.

The remaining reusable logic lives in Base: before removing a managed section, update-profile needs to know whether a target file contains the full-line marker pair so it can report dry-run output and create backups only when removal would actually change the file.

Proposed shape

Add a public lib/bash/file/lib_file.sh helper for marker-delimited section inspection, for example file_section_exists or file_section_needs_change, that callers can use before update_file_section -r.

The helper should reuse the same semantics as update_file_section:

  • Treat markers as exact full lines.
  • Reject asymmetric or misordered marker pairs with the same manual-repair posture.
  • Return a clean no-change result when the target file is missing or the section is absent.
  • Avoid modifying the target file.
  • Be suitable for dry-run and backup decisions in Base callers.

Acceptance criteria

  • lib/bash/file/lib_file.sh exposes a documented public helper for section inspection.
  • BATS coverage includes present, absent, missing-file, asymmetric-marker, and misordered-marker cases.
  • lib/bash/file/README.md documents the helper and its return contract.
  • A follow-up Base PR can replace base_update_profile_remove_file_needs_change with the shared helper after this lands.

Related: basefoundry/base#1366, basefoundry/base#1380

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or product improvement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions