aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/paths.go
blob: 3316a22e731bfc9363be47071ce9bdc5fdd0c179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package app

import (
	"strconv"

	"hakurei.app/container"
	"hakurei.app/hst"
)

// CopyPaths populates a [hst.Paths] struct.
func CopyPaths(v *hst.Paths, userid int) { copyPaths(direct{}, v, userid) }

// copyPaths populates a [hst.Paths] struct.
func copyPaths(k syscallDispatcher, v *hst.Paths, userid int) {
	const xdgRuntimeDir = "XDG_RUNTIME_DIR"

	if tempDir, err := container.NewAbs(k.tempdir()); err != nil {
		k.fatalf("invalid TMPDIR: %v", err)
	} else {
		v.TempDir = tempDir
	}

	v.SharePath = v.TempDir.Append("hakurei." + strconv.Itoa(userid))
	k.verbosef("process share directory at %q", v.SharePath)

	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")
	}
	k.verbosef("runtime directory at %q", v.RunDirPath)
}