Relationships
#1655 @adam/cfgmgmt/directory: uses GNU stat -c, silently non-compliant on FreeBSD and macOS targets
Opened by josephholsten · 8/14/2026
Summary
@adam/cfgmgmt/directory uses stat -c '%F|%U|%G|%a' in its gather() function to read directory state on remote hosts. This is GNU coreutils syntax. BSD stat (FreeBSD, macOS) uses -f for format strings, not -c.
Impact
When the model targets a FreeBSD or macOS host, the stat command exits 0 but produces no output. The gather() function interprets this as "NOTFOUND" and returns exists: false. As a result:
checkalways reportsnon_complianteven when the directory existsapplyrunsmkdiridempotently but subsequentcheckstill reportsnon_compliant- No error is surfaced — the failure is silent
Reproduction
Configure a @adam/cfgmgmt/directory model against a FreeBSD host. Run check against a directory that exists. Result: status: non_compliant, current.exists: false.
Root cause
In directory.ts, the gather function:
const statResult = await execSudo(
client,
`stat -c '%F|%U|%G|%a' ${shellEscape(path)} 2>/dev/null || echo 'NOTFOUND'`,
so,
);On BSD, stat -c is an unknown option; the command fails and the || echo 'NOTFOUND' branch fires.
Fix
Use a POSIX-compatible alternative. Options:
- Detect platform and branch on stat syntax (
stat -con Linux,stat -fon BSD) - Use
ls -ld+awkwhich is POSIX and works on all platforms - Document that
@adam/cfgmgmt/directoryrequires GNU coreutils on the target host
Notes
Discovered during LIM-82 (lilwoods-corde) while managing directories on a FreeBSD 14 host. @adam/cfgmgmt/line and @adam/cfgmgmt/authorized_key use test -f, cat, and getent — all POSIX-compatible and working correctly on FreeBSD.
Closed
No activity in this phase yet.