aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/paths.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-30 00:21:26 +0900
committerOphestra <cat@gensokyo.uk>2025-09-30 00:21:26 +0900
commite58181a930064385c881b7ee1cac4914dd435121 (patch)
treef9ee955ebf054e8a1dcb8d8a3e623a47f0d5ab77 /internal/app/paths.go
parent71e70b7b5feb94aab5d99d9a3c2bea54537632c4 (diff)
internal/app/paths: defer extra formatting
This reduces payload size for params to shim. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/paths.go')
-rw-r--r--internal/app/paths.go53
1 files changed, 39 insertions, 14 deletions
diff --git a/internal/app/paths.go b/internal/app/paths.go
index 267d0eab..4305c665 100644
--- a/internal/app/paths.go
+++ b/internal/app/paths.go
@@ -7,28 +7,53 @@ import (
"hakurei.app/hst"
)
-// CopyPaths populates a [hst.Paths] struct.
-func CopyPaths(v *hst.Paths, userid int) { copyPaths(direct{}, v, userid) }
+// EnvPaths holds paths copied from the environment and is used to create [hst.Paths].
+type EnvPaths struct {
+ // TempDir is returned by [os.TempDir].
+ TempDir *container.Absolute
+ // RuntimePath is copied from $XDG_RUNTIME_DIR.
+ RuntimePath *container.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")
+ }
-// copyPaths populates a [hst.Paths] struct.
-func copyPaths(k syscallDispatcher, v *hst.Paths, userid int) {
+ 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 := container.NewAbs(k.tempdir()); err != nil {
k.fatalf("invalid TMPDIR: %v", err)
+ panic("unreachable")
} else {
- v.TempDir = tempDir
+ env.TempDir = tempDir
}
- v.SharePath = v.TempDir.Append("hakurei." + strconv.Itoa(userid))
-
r, _ := k.lookupEnv(xdgRuntimeDir)
- if a, err := container.NewAbs(r); err != 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 = a
- v.RunDirPath = v.RuntimePath.Append("hakurei")
+ if a, err := container.NewAbs(r); err == nil {
+ env.RuntimePath = a
}
+
+ return &env
}