aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/ensure.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-09-22 00:29:36 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-09-22 01:15:39 +0900
commit62cb8a91b603546314034ded1e9d6ddfbd6ef106 (patch)
tree981d0c6daf04595e0118f8a48c0898cdd6d44e05 /internal/app/ensure.go
parent11832a937924030699a6304a3ba9b5884532b730 (diff)
app: clean up interactions and handle all application state and setup/teardown
There was an earlier attempt of cleaning up the app package however it ended up creating even more of a mess and the code structure largely still looked like Ego with state setup scattered everywhere and a bunch of ugly hacks had to be implemented to keep track of all of them. In this commit the entire app package is rewritten to track everything that has to do with an app in one thread safe value. In anticipation of the client/server split also made changes: - Console messages are cleaned up to be consistent - State tracking is fully rewritten to be cleaner and usable for multiple process and client/server - Encapsulate errors to easier identify type of action causing the error as well as additional info - System-level setup operations is grouped in a way that can be collectively committed/reverted and gracefully handles errors returned by each operation - Resource sharing is made more fine-grained with PID-scoped resources whenever possible, a few remnants (X11, Wayland, PulseAudio) will be addressed when a generic proxy is available - Application setup takes a JSON-friendly config struct and deterministically generates system setup operations Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app/ensure.go')
-rw-r--r--internal/app/ensure.go63
1 files changed, 0 insertions, 63 deletions
diff --git a/internal/app/ensure.go b/internal/app/ensure.go
deleted file mode 100644
index ed283a94..00000000
--- a/internal/app/ensure.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package app
-
-import (
- "errors"
- "fmt"
- "io/fs"
- "os"
- "path"
-
- "git.ophivana.moe/cat/fortify/acl"
- "git.ophivana.moe/cat/fortify/internal"
- "git.ophivana.moe/cat/fortify/internal/verbose"
-)
-
-func (a *App) EnsureRunDir() {
- if err := os.Mkdir(a.runDirPath, 0700); err != nil && !errors.Is(err, fs.ErrExist) {
- internal.Fatal("Error creating runtime directory:", err)
- }
-}
-
-func (a *App) EnsureRuntime() {
- if s, err := os.Stat(a.runtimePath); err != nil {
- if errors.Is(err, fs.ErrNotExist) {
- internal.Fatal("Runtime directory does not exist")
- }
- internal.Fatal("Error accessing runtime directory:", err)
- } else if !s.IsDir() {
- internal.Fatal(fmt.Sprintf("Path '%s' is not a directory", a.runtimePath))
- } else {
- if err = acl.UpdatePerm(a.runtimePath, a.UID(), acl.Execute); err != nil {
- internal.Fatal("Error preparing runtime directory:", err)
- } else {
- a.exit.RegisterRevertPath(a.runtimePath)
- }
- verbose.Printf("Runtime data dir '%s' configured\n", a.runtimePath)
- }
-}
-
-func (a *App) EnsureShare() {
- // acl is unnecessary as this directory is world executable
- if err := os.Mkdir(a.sharePath, 0701); err != nil && !errors.Is(err, fs.ErrExist) {
- internal.Fatal("Error creating shared directory:", err)
- }
-
- // workaround for launch method sudo
- if a.LaunchOption() == LaunchMethodSudo {
- // ensure child runtime directory (e.g. `/tmp/fortify.%d/%d.share`)
- cr := path.Join(a.sharePath, a.Uid+".share")
- if err := os.Mkdir(cr, 0700); err != nil && !errors.Is(err, fs.ErrExist) {
- internal.Fatal("Error creating child runtime directory:", err)
- } else {
- if err = acl.UpdatePerm(cr, a.UID(), acl.Read, acl.Write, acl.Execute); err != nil {
- internal.Fatal("Error preparing child runtime directory:", err)
- } else {
- a.exit.RegisterRevertPath(cr)
- }
- a.AppendEnv("XDG_RUNTIME_DIR", cr)
- a.AppendEnv("XDG_SESSION_CLASS", "user")
- a.AppendEnv("XDG_SESSION_TYPE", "tty")
- verbose.Printf("Child runtime data dir '%s' configured\n", cr)
- }
- }
-}