summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-22 21:33:31 +0200
committerewy <ewy0@protonmail.com>2026-04-22 21:33:31 +0200
commitdeebd135ffcb1c167f12ecf2d4c0aebdc14cbc86 (patch)
tree82bb2a78c561759c3256e8d6b0caa71c06bbf028
parent7f3e0d7da81d2c64a507a60d5bea9af8e4464fcb (diff)
allow re-setting of variables so i can add unit tests later
-rw-r--r--paths/paths.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/paths/paths.go b/paths/paths.go
index 80928df..9f27385 100644
--- a/paths/paths.go
+++ b/paths/paths.go
@@ -7,20 +7,30 @@ import (
"strings"
)
-var (
- Home = xdg.Home
- This = "pik"
- Cache = filepath.Join(xdg.CacheHome, This)
- Config = filepath.Join(xdg.ConfigHome, This)
- Ifs = os.Getenv("IFS")
-)
+var Home, This, Cache, Config, Ifs string
type paths struct {
+ Initialized bool
+}
+
+var Paths = &paths{
+ Initialized: false,
}
-var Paths = &paths{}
+func (p *paths) Init() error {
+
+ // if we're asked to initialize for a second time,
+ // probably some environment has changed
+ if p.Initialized {
+ xdg.Reload()
+ }
+
+ Home = xdg.Home
+ This = "pik"
+ Cache = filepath.Join(xdg.CacheHome, This)
+ Config = filepath.Join(xdg.ConfigHome, This)
+ Ifs = os.Getenv("IFS")
-func (p paths) Init() error {
err := os.MkdirAll(Cache, 0700)
if err != nil {
return err
@@ -32,6 +42,7 @@ func (p paths) Init() error {
if Ifs == "" {
Ifs = "\n"
}
+ p.Initialized = true
return nil
}