feat: EnsureSystemdKey — idempotent systemd unit directive (v0.14.0)#10
Merged
Conversation
Adds porter.EnsureSystemdKey(path, section, key, value): ensures a key=value directive under a systemd unit's [section] (Unit/Service/Timer/Install), inserting it directly after the section header rather than appending a stray line at EOF the way EnsureLine would. Idempotent — no-ops when the key is already present anywhere (a hand-edited value wins) — preserves CRLF, and preserves the unit's mode/owner on rewrite (cp over the existing file). .Sudo() for units under /etc/systemd/system. General-use gap surfaced by bulk's deploy code, which hand-rolls the same section-aware key insertion over a raw SSH client (casino/systemd EnsureServiceKey/EnsureUnitKey); porter's EnsureLine couldn't target a section. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
porter.EnsureSystemdKey(path, section, key, value)— idempotently ensures akey=valuedirective under a systemd unit's[section](Unit/Service/Timer/Install).EnsureLinecould only append a stray line at EOF.key=line is already present anywhere (a hand-edited value wins).cpover the existing file)..Sudo()for units under/etc/systemd/system; follow withRun("systemctl daemon-reload").Why
General-use gap surfaced reviewing bulk's deploy code (idnerdidx/bulk#396), which hand-rolls exactly this section-aware key insertion over a raw SSH client (
casino/systemdEnsureServiceKey/EnsureUnitKey). Porter'sEnsureLineappends at EOF, which is wrong for a sectioned INI file — so any deploy needingRestart=,ExecStartPre=,After=, etc. had to drop out of porter. This closes that.Tests
Pure-function coverage (insert placement, no-op-when-present, missing-section error, CRLF) in
features_test.go; read→insert→write + no-op dispatch via the fake runner inruntime_test.go. Full suite green;go vet/gofmtclean. Bumps version to 0.14.0.🤖 Generated with Claude Code