Skip to content

Remove dead helper functions#14

Merged
wnstfy merged 6 commits into
developfrom
chore/dead-code-helpers
Jun 21, 2026
Merged

Remove dead helper functions#14
wnstfy merged 6 commits into
developfrom
chore/dead-code-helpers

Conversation

@wnstfy

@wnstfy wnstfy commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of a grouped dead-code cleanup (3 PRs, split by area). This PR removes zero-caller helper functions across several modules.

Changes (5 atomic commits)

  • lib/core.sh — remove run_tracked_command, json_kv, check_disk_space, check_network, safe_write_file, create_mysql_auth_file, get_all_panel_keys, get_site_name, sanitize_for_filename (the last two were duplicated by the generated-script copies in generators.sh, which the backup scripts actually use); drops the matching sanitize_for_filename unit tests
  • lib/history.sh — remove get_job_history, get_history_by_jobs (per-job history reporting never wired into the CLI)
  • lib/crypto.sh — remove migration_recommended, get_migration_recommendation (backupd.sh does the version comparison inline)
  • lib/generators.sh — remove generate_default_job_scripts_from_config (no callers)
  • install.sh — remove get_install_hint (installer never calls it; the maintained copy is in lib/core.sh)

369 lines removed.

Scope note

Only functions with zero callers. Two related items were deliberately left out of this batch for a separate review because they are behaviour-adjacent rather than dead: trimming the lib/logging.sh instrumentation (its internal call graph needs care) and pruning the unused EXIT_* constants in lib/exitcodes.sh (a small, tested sysexits.h reference table).

Testing

  • ./tests/run-tests.sh --syntax — 22 files pass
  • ./tests/run-tests.sh --unit — all unit tests pass (162; the 7 removed tests covered the deleted sanitize_for_filename)
  • shellcheck -x -s bash -S warning backupd.sh lib/*.sh — clean

Targets develop. Hold for green CI + review before merge.

wnstfy added 5 commits June 21, 2026 14:21
run_tracked_command, json_kv, check_disk_space, check_network,
safe_write_file, create_mysql_auth_file, get_all_panel_keys, get_site_name
and sanitize_for_filename have no callers. get_site_name and
sanitize_for_filename were duplicated by the generated-script copies in
generators.sh, which is what the backup scripts actually use. Drops the
matching sanitize_for_filename unit tests.
get_job_history and get_history_by_jobs have no callers; per-job history
reporting was never wired into the CLI.
migration_recommended and get_migration_recommendation have no callers;
backupd.sh computes the version comparison inline in its encryption-status
and migrate flows.
No callers anywhere; migration generates default-job scripts through
generate_job_scripts instead.
The installer never calls get_install_hint. The maintained copy lives in
lib/core.sh (used by lib/crypto.sh); the install.sh copy was dead.
@greptile-apps

greptile-apps Bot commented Jun 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR removes 369 lines of confirmed-dead helper functions across five files as part of a grouped dead-code cleanup. Every removed symbol was verified to have zero callers in the live codebase, and the matching USAGE.md documentation for the history API was updated in the same changeset, addressing the concern raised in a previous review thread.

  • lib/core.sh loses nine helpers (run_tracked_command, json_kv, check_disk_space, check_network, safe_write_file, create_mysql_auth_file, get_all_panel_keys, get_site_name, sanitize_for_filename); the active get_site_name/sanitize_for_tag copies used by generated backup scripts remain in lib/generators.sh.
  • lib/history.sh, lib/crypto.sh, lib/generators.sh, and install.sh each shed one or two unused functions, with the maintained get_install_hint copy staying in lib/core.sh where it is actually called.
  • Seven sanitize_for_filename unit tests are removed together with the function itself, keeping the test suite consistent.

Confidence Score: 5/5

Safe to merge — every removed function was confirmed to have zero callers, and the USAGE.md documentation was updated in the same changeset.

All deletions were cross-referenced against the full codebase: no live caller was found for any removed symbol. The get_install_hint duplicate in install.sh was correctly identified as redundant because the maintained copy in lib/core.sh is what backupd.sh and lib/crypto.sh actually call. The active get_site_name/sanitize_for_tag copies used by the generated backup scripts remain untouched in lib/generators.sh. The only noteworthy side-effect is an unintentional execute-bit removal on four files, which does not affect the documented curl | bash installation path.

No files require special attention; the execute-bit change on install.sh is worth a quick git update-index --chmod=+x before merging if direct invocation is expected.

Important Files Changed

Filename Overview
lib/core.sh Removes 9 dead helper functions (run_tracked_command, json_kv, check_disk_space, check_network, safe_write_file, create_mysql_auth_file, get_all_panel_keys, get_site_name, sanitize_for_filename); grep confirms no callers remain. File mode also changed from 755→644.
lib/history.sh Removes get_job_history and get_history_by_jobs; no callers in codebase, and the matching USAGE.md documentation was updated in the same PR.
lib/crypto.sh Removes migration_recommended and get_migration_recommendation; backupd.sh performs the version comparison inline, so these wrappers had no callers. File mode changed from 755→644.
lib/generators.sh Removes generate_default_job_scripts_from_config (confirmed zero callers); the live get_site_name/sanitize_for_tag copies used by the generated backup scripts remain intact at lines 741–789. File mode changed from 755→644.
install.sh Removes get_install_hint (confirmed the maintained copy in lib/core.sh is still present and called by backupd.sh and lib/crypto.sh). File mode changed from 755→644, which is unintentional for an installer script.
tests/unit/core.bats Correctly drops 7 sanitize_for_filename tests that exclusively covered the now-deleted function; no other test coverage is affected.
USAGE.md Removes the programmatic API examples for get_job_history and get_history_by_jobs that were flagged in a previous review thread; the remaining history section still references the CLI command.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Dead Code Removal PR] --> B[lib/core.sh\n9 functions removed]
    A --> C[lib/history.sh\n2 functions removed]
    A --> D[lib/crypto.sh\n2 functions removed]
    A --> E[lib/generators.sh\n1 function removed]
    A --> F[install.sh\n1 function removed]
    A --> G[USAGE.md\nAPI examples removed]
    A --> H[tests/unit/core.bats\n7 tests removed]
    B --> B1["get_install_hint kept in core.sh\n→ still called by backupd.sh + crypto.sh"]
    B --> B2["get_site_name active copy\n→ remains in generators.sh:752"]
    B --> B3["sanitize_for_filename no callers\n→ sanitize_for_tag in generators.sh used instead"]
    F --> F1["get_install_hint removed from install.sh\n(duplicate — live copy is in lib/core.sh)"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Dead Code Removal PR] --> B[lib/core.sh\n9 functions removed]
    A --> C[lib/history.sh\n2 functions removed]
    A --> D[lib/crypto.sh\n2 functions removed]
    A --> E[lib/generators.sh\n1 function removed]
    A --> F[install.sh\n1 function removed]
    A --> G[USAGE.md\nAPI examples removed]
    A --> H[tests/unit/core.bats\n7 tests removed]
    B --> B1["get_install_hint kept in core.sh\n→ still called by backupd.sh + crypto.sh"]
    B --> B2["get_site_name active copy\n→ remains in generators.sh:752"]
    B --> B3["sanitize_for_filename no callers\n→ sanitize_for_tag in generators.sh used instead"]
    F --> F1["get_install_hint removed from install.sh\n(duplicate — live copy is in lib/core.sh)"]
Loading

Reviews (2): Last reviewed commit: "Drop removed-function examples from hist..." | Re-trigger Greptile

Comment thread lib/history.sh
@@ -112,70 +112,3 @@ get_next_backup_times() {
local verify_full_next=$(echo "$timer_out" | grep "backupd-verify-full.timer" | awk '{print $1, $2, $3}')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Documented public API removed without updating USAGE.md

get_job_history and get_history_by_jobs are explicitly advertised in USAGE.md (lines 1222-1235) as a programmatic interface that users are instructed to call by directly sourcing history.sh. Any user script following that documentation will silently get a command not found error after this change. The removal is fine if these functions are truly unused, but USAGE.md needs a matching update to remove (or redirect) those code examples.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — addressed in 05720dd. get_job_history/get_history_by_jobs had zero callers in the codebase (the CLI's backupd job show <job> computes per-job history with its own inline logic, not these functions), so they were genuinely dead. I've removed the now-stale programmatic examples from USAGE.md's Job-Specific History section and kept the supported sudo backupd job show <job> path. No more dangling source history.sh; get_job_history ... docs that would hit command-not-found.

get_job_history and get_history_by_jobs were removed as dead code; USAGE.md
still advertised them as a programmatic interface to source directly, which
would now fail with "command not found". Keep the supported CLI path
(backupd job show <job>) for per-job history.
@wnstfy
wnstfy merged commit 215caba into develop Jun 21, 2026
4 checks passed
@wnstfy
wnstfy deleted the chore/dead-code-helpers branch June 21, 2026 12:57
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