is_unit_disabled mapped any canonicalize() error to "disabled" via
unwrap_or(true), conflating ENOENT with transient I/O failures. For
new_dropins.all(is_unit_disabled) that meant a transient error on a
still-present drop-in could read as "all masked" and stop a unit that
is still configured.
Replace the boolean helper with a tri-state UnitFileState (Present /
Masked / Missing) returned from unit_file_state(). Only ENOENT maps to
Missing; other errors are propagated so callers cannot accidentally
pick the wrong default.
canonicalize() only needs &self, so there is no reason to take ownership
of the PathBuf. Accepting impl AsRef<Path> lets the glob iterator call
sites keep passing owned PathBufs to .all() while the direct call on
new_base_unit_file no longer needs to clone.
Unit names may contain backslashes (e.g. from systemd-escape) and the
toplevel path is user-influenced; both were previously fed unescaped
into glob() where they could be misinterpreted as metacharacters and
silently match nothing.
Factor the pattern into a helper that escapes the path prefix and use
it at all four call sites.
As the test shows, stc-ng previously did not correctly account for the
removal of template instances defined with overrideStrategy "asDropin".
A real use case does exist: Defining systemd-nspawn container units
which inherit the settings from the vendored systemd-nspawn@.service.
I tried to find the least intrusvie but stable solution here. The
globbing is technically unnecessary but it mimics the behaviour and
implementation in parse_unit.
allowGoReference was added in 5a69b0b3c4 (2024-04-29) with the
comment 'allowGoReference adds the flag -trimpath'. This is
backwards: allowGoReference = true *disables* -trimpath and *allows*
the Go compiler to remain in the runtime closure (257 MiB).
The package builds and passes all tests without it. Dropping it
re-enables -trimpath and shrinks the runtime closure from 263.6 MiB
to 8.6 MiB.
Add two shouldPass tests that catch known yj regressions:
- tomlHeterogeneousArray: arrays mixing scalars and attrsets crash yj
with 'unexpected primitive type' (NixOS/nixpkgs#511970)
- tomlCommaInKey: keys containing commas are silently truncated
because yj stores TOML keys in Go struct tags where commas are
option separators (sclevine/yj#52)
Expected values are taken from go-toml's jsontoml output.
Both tests fail under the current yj backend.