paths: skip the user search tier when there is no home directory

ConfigSearchDirs/DataSearchDirs/ExecutableSearchDirs (and therefore
core/config's Resolve/ResolveAll/LoadMerged) failed outright with
ErrNoHomeDirectory when HOME/USERPROFILE was unset, so a service
started without HOME could no longer find its working-directory or
/etc/<app> config -- a regression against the hand-rolled lookups
being migrated onto core, which just skipped the user location.
Missing-home now only drops the user tier from the search lists; the
canonical <Category>Dir() methods still report ErrNoHomeDirectory.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-09-22 22:24:51 +02:00
1 parent 72b656262d
commit e8bf23a064
7 files changed
+220 -57

No files matched your search

+21 -1
View File
@@ -1,6 +1,10 @@
package paths
import "yetano.dev/yetano/core"
import (
"errors"
"yetano.dev/yetano/core"
)
// layer is one directory in a search/priority hierarchy (see
// AGENTS.md-style docs in paths.go: "canonical path vs. search paths").
@@ -40,6 +44,22 @@ func composeSearch(user, system []layer, scope core.Scope) []layer {
return out
}
// skipMissingHome filters a user-tier lookup error for the search-dir
// builders (Config/Data/Executable): a missing home directory only means
// there is no user tier to search -- the working-directory and system
// tiers are still meaningful (e.g. a system service started without
// HOME whose config lives in /etc/<app>), so ErrNoHomeDirectory is
// dropped here and the caller simply omits its user layer(s). Any other
// error is returned unchanged. The canonical <Category>Dir() methods are
// unaffected and still report ErrNoHomeDirectory: a write location is
// never silently swapped for a different tier.
func skipMissingHome(err error) error {
if errors.Is(err, ErrNoHomeDirectory) {
return nil
}
return err
}
// envSuffix maps each category to the "_HOME" suffix used to build its
// YETANO_*/<PREFIX>_* environment variable names (e.g. ConfigPath ->
// "YETANO_CONFIG_HOME" / "YET_CONFIG_HOME").