aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-03 16:59:29 +0900
committerOphestra <cat@gensokyo.uk>2025-10-03 16:59:29 +0900
commita5f0aa3f3077cb7bf3cbf7ac9e707ba165aceb4a (patch)
treef75910d2147ac7c02328d229a8cb8609d2355016
parentdd0bb0a39104a54c26015df807c1eb113331c242 (diff)
internal/app: declutter and merge small files
This should make internal/app easier to work with for the upcoming params to shim. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/hakurei/command.go23
-rw-r--r--internal/app/env.go (renamed from internal/app/paths.go)0
-rw-r--r--internal/app/env_test.go (renamed from internal/app/paths_test.go)0
-rw-r--r--internal/app/finalise.go11
-rw-r--r--internal/app/path.go6
-rw-r--r--internal/app/strings.go16
6 files changed, 20 insertions, 36 deletions
diff --git a/cmd/hakurei/command.go b/cmd/hakurei/command.go
index ddd07bac..0c3e5e7a 100644
--- a/cmd/hakurei/command.go
+++ b/cmd/hakurei/command.go
@@ -237,25 +237,10 @@ func buildCommand(ctx context.Context, msg container.Msg, early *earlyHardeningE
}).Flag(&flagShort, "short", command.BoolFlag(false), "Print instance id")
}
- c.Command("version", "Display version information", func(args []string) error {
- fmt.Println(internal.Version())
- return errSuccess
- })
-
- c.Command("license", "Show full license text", func(args []string) error {
- fmt.Println(license)
- return errSuccess
- })
-
- c.Command("template", "Produce a config template", func(args []string) error {
- printJSON(os.Stdout, false, hst.Template())
- return errSuccess
- })
-
- c.Command("help", "Show this help message", func([]string) error {
- c.PrintHelp()
- return errSuccess
- })
+ c.Command("version", "Display version information", func(args []string) error { fmt.Println(internal.Version()); return errSuccess })
+ c.Command("license", "Show full license text", func(args []string) error { fmt.Println(license); return errSuccess })
+ c.Command("template", "Produce a config template", func(args []string) error { printJSON(os.Stdout, false, hst.Template()); return errSuccess })
+ c.Command("help", "Show this help message", func([]string) error { c.PrintHelp(); return errSuccess })
return c
}
diff --git a/internal/app/paths.go b/internal/app/env.go
index 4305c665..4305c665 100644
--- a/internal/app/paths.go
+++ b/internal/app/env.go
diff --git a/internal/app/paths_test.go b/internal/app/env_test.go
index 04e21344..04e21344 100644
--- a/internal/app/paths_test.go
+++ b/internal/app/env_test.go
diff --git a/internal/app/finalise.go b/internal/app/finalise.go
index a33bcc91..d2459421 100644
--- a/internal/app/finalise.go
+++ b/internal/app/finalise.go
@@ -26,6 +26,17 @@ import (
"hakurei.app/system/wayland"
)
+func newInt(v int) *stringPair[int] { return &stringPair[int]{v, strconv.Itoa(v)} }
+
+// stringPair stores a value and its string representation.
+type stringPair[T comparable] struct {
+ v T
+ s string
+}
+
+func (s *stringPair[T]) unwrap() T { return s.v }
+func (s *stringPair[T]) String() string { return s.s }
+
func newWithMessage(msg string) error { return newWithMessageError(msg, os.ErrInvalid) }
func newWithMessageError(msg string, err error) error {
return &hst.AppError{Step: "finalise", Err: err, Msg: msg}
diff --git a/internal/app/path.go b/internal/app/path.go
index 56e373d9..493dfe39 100644
--- a/internal/app/path.go
+++ b/internal/app/path.go
@@ -6,6 +6,10 @@ import (
)
func deepContainsH(basepath, targpath string) (bool, error) {
+ const upper = ".." + string(filepath.Separator)
+
rel, err := filepath.Rel(basepath, targpath)
- return err == nil && rel != ".." && !strings.HasPrefix(rel, string([]byte{'.', '.', filepath.Separator})), err
+ return err == nil &&
+ rel != ".." &&
+ !strings.HasPrefix(rel, upper), err
}
diff --git a/internal/app/strings.go b/internal/app/strings.go
deleted file mode 100644
index a7fdcd46..00000000
--- a/internal/app/strings.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package app
-
-import (
- "strconv"
-)
-
-func newInt(v int) *stringPair[int] { return &stringPair[int]{v, strconv.Itoa(v)} }
-
-// stringPair stores a value and its string representation.
-type stringPair[T comparable] struct {
- v T
- s string
-}
-
-func (s *stringPair[T]) unwrap() T { return s.v }
-func (s *stringPair[T]) String() string { return s.s }