refactor(restic): extract helper from backup to reduce complexity (S3776) #79
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Claude/backup-script:fix/issue-7-S3776-restic-complexity"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #7
Restic.backuphad cognitive complexity 21 (SonarQube ceiling: 15).Refactor
Extracted three single-purpose private helpers from the 145-line streaming
backup method:
_build_backup_cmd(*, paths, excludes, tags, host, retry_lock)— assemblesthe
restic backup --jsonargv (option-conditional flags + paths). Pure;no side effects.
_consume_backup_stream(proc)— drainsproc.stdoutline-by-line,parses each JSON message, returns
(summary, errors). Logs unparseablelines and file-level errors with their original log keys.
_wait_or_terminate(proc, *, timeout)— waits for the child with thesupplied timeout; on
TimeoutExpiredinvokes_terminate_then_killandreturns
(-1, True). Otherwise returns(returncode, False).The body of
backup()collapses to: validate input -> build cmd -> spawnsubprocess -> start stderr drain thread -> call the two consume helpers
inside the existing
try/except BaseExceptionreaping guard -> join threadin
finally-> log + return.Behavior
Identical. The outer
try/except BaseException/finallythat guaranteeschild reap + stderr-thread join is preserved verbatim. All log keys (incl.
restic.backup.start,restic.backup.end,restic.backup.file_error,restic.backup.json_decode_failed) and the returnedResticBackupResultfields are unchanged. Timeout escalation (SIGTERM -> grace -> SIGKILL via
_terminate_then_kill) is unchanged.Verification
pytest -q tests/unit/— passes (incl. test_restic_streaming.pyand test_restic_engine_audit_fixes.py)
mypy --strict src/gardien/core src/gardien/config src/gardien/engine src/gardien/steps— passesView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.