diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-29 04:09:42 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-29 04:11:49 +0900 |
| commit | a52f7038e5a607dd0901244abb791c96deaf9c2d (patch) | |
| tree | 2184b7313cf3b2d783778e8272ac22d0eaa1603f /internal/app/env.go | |
| parent | 274686d10d3386a41f8fb6bc3363269a734afe0e (diff) | |
internal/env: relocate from app
This package is much cleaner to stub independently, and makes no sense to lump into app.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/env.go')
| -rw-r--r-- | internal/app/env.go | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/internal/app/env.go b/internal/app/env.go deleted file mode 100644 index e6d137fc..00000000 --- a/internal/app/env.go +++ /dev/null @@ -1,59 +0,0 @@ -package app - -import ( - "strconv" - - "hakurei.app/container/check" - "hakurei.app/hst" -) - -// EnvPaths holds paths copied from the environment and is used to create [hst.Paths]. -type EnvPaths struct { - // TempDir is returned by [os.TempDir]. - TempDir *check.Absolute - // RuntimePath is copied from $XDG_RUNTIME_DIR. - RuntimePath *check.Absolute -} - -// Copy expands [EnvPaths] into [hst.Paths]. -func (env *EnvPaths) Copy(v *hst.Paths, userid int) { - if env == nil || env.TempDir == nil || v == nil { - panic("attempting to use an invalid EnvPaths") - } - - v.TempDir = env.TempDir - v.SharePath = env.TempDir.Append("hakurei." + strconv.Itoa(userid)) - - if env.RuntimePath == nil { - // fall back to path in share since hakurei has no hard XDG dependency - v.RunDirPath = v.SharePath.Append("run") - v.RuntimePath = v.RunDirPath.Append("compat") - } else { - v.RuntimePath = env.RuntimePath - v.RunDirPath = env.RuntimePath.Append("hakurei") - } -} - -// CopyPaths returns a populated [EnvPaths]. -func CopyPaths() *EnvPaths { return copyPaths(direct{}) } - -// copyPaths returns a populated [EnvPaths]. -func copyPaths(k syscallDispatcher) *EnvPaths { - const xdgRuntimeDir = "XDG_RUNTIME_DIR" - - var env EnvPaths - - if tempDir, err := check.NewAbs(k.tempdir()); err != nil { - k.fatalf("invalid TMPDIR: %v", err) - panic("unreachable") - } else { - env.TempDir = tempDir - } - - r, _ := k.lookupEnv(xdgRuntimeDir) - if a, err := check.NewAbs(r); err == nil { - env.RuntimePath = a - } - - return &env -} |
