From 2220055e26bff8b426ebf086d09ba242e5180e76 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Thu, 10 Oct 2024 11:03:31 +0900 Subject: [PATCH] state/simple: prefix store path Signed-off-by: Ophestra Umiker --- internal/state/print.go | 9 ++++----- internal/state/simple.go | 5 ++--- state.go | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/state/print.go b/internal/state/print.go index 5ad7cac..8de5a59 100644 --- a/internal/state/print.go +++ b/internal/state/print.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" "os" "path" @@ -9,18 +10,16 @@ import ( "text/tabwriter" "time" - "git.ophivana.moe/cat/fortify/internal" "git.ophivana.moe/cat/fortify/internal/verbose" ) // MustPrintLauncherStateSimpleGlobal prints active launcher states of all simple stores // in an implementation-specific way. -func MustPrintLauncherStateSimpleGlobal(w **tabwriter.Writer) { - sc := internal.GetSC() +func MustPrintLauncherStateSimpleGlobal(w **tabwriter.Writer, runDir string) { now := time.Now().UTC() // read runtime directory to get all UIDs - if dirs, err := os.ReadDir(sc.RunDirPath); err != nil { + if dirs, err := os.ReadDir(path.Join(runDir, "state")); err != nil && !errors.Is(err, os.ErrNotExist) { fmt.Println("cannot read runtime directory:", err) os.Exit(1) } else { @@ -38,7 +37,7 @@ func MustPrintLauncherStateSimpleGlobal(w **tabwriter.Writer) { } // obtain temporary store - s := NewSimple(sc.RunDirPath, e.Name()).(*simpleStore) + s := NewSimple(runDir, e.Name()).(*simpleStore) // print states belonging to this store s.mustPrintLauncherState(w, now) diff --git a/internal/state/simple.go b/internal/state/simple.go index a18d152..ad3e472 100644 --- a/internal/state/simple.go +++ b/internal/state/simple.go @@ -211,9 +211,8 @@ func (b *simpleBackend) Len() (int, error) { } // NewSimple returns an instance of a file-based store. -// Store prefix is typically (runDir, uid). -func NewSimple(prefix ...string) Store { +func NewSimple(runDir string, prefix ...string) Store { b := new(simpleStore) - b.path = prefix + b.path = append([]string{runDir, "state"}, prefix...) return b } diff --git a/state.go b/state.go index 96bddff..5454fb7 100644 --- a/state.go +++ b/state.go @@ -6,6 +6,7 @@ import ( "os" "text/tabwriter" + "git.ophivana.moe/cat/fortify/internal" "git.ophivana.moe/cat/fortify/internal/state" ) @@ -21,7 +22,7 @@ func init() { func tryState() { if stateActionEarly { var w *tabwriter.Writer - state.MustPrintLauncherStateSimpleGlobal(&w) + state.MustPrintLauncherStateSimpleGlobal(&w, internal.GetSC().RunDirPath) if w != nil { if err := w.Flush(); err != nil { fmt.Println("warn: error formatting output:", err)