From 9d8c43cd68c960b9a6b8f781684f763e204a4498 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 5 Oct 2026 18:16:47 -0400 Subject: fix: shared YAML encoder and journal directory, text cleanup --- internal/admin/yaml_util.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'internal/admin/yaml_util.go') diff --git a/internal/admin/yaml_util.go b/internal/admin/yaml_util.go index e1d4942..2ab7ec4 100644 --- a/internal/admin/yaml_util.go +++ b/internal/admin/yaml_util.go @@ -1,15 +1,13 @@ package admin import ( - "bytes" "fmt" "log" "os" "path/filepath" "strings" - "gopkg.in/yaml.v3" - + "thehouseoficarus/internal/behavior" "thehouseoficarus/internal/persistence" ) @@ -20,16 +18,7 @@ func readYAMLFile(dataDir, subdir, id string) ([]byte, string, error) { } func marshalYAML(data any) ([]byte, error) { - var buf bytes.Buffer - enc := yaml.NewEncoder(&buf) - enc.SetIndent(2) - if err := enc.Encode(data); err != nil { - return nil, err - } - if err := enc.Close(); err != nil { - return nil, err - } - return buf.Bytes(), nil + return behavior.MarshalYAML(data) } func writeYAMLFile(path string, data any) ([]byte, error) { @@ -214,7 +203,7 @@ func moveEntityFile(dataDir, subdir, id, targetDir string) (string, string, []by } // Move in one journaled transaction: a failed write or source removal // must not leave the entity in two directories. - txn := persistence.NewTransaction(filepath.Join(dataDir, ".journal")) + txn := persistence.NewTransaction(persistence.JournalDir(dataDir)) if err := txn.Move(oldPath, newPath); err != nil { return "", "", nil, fmt.Errorf("move: %w", err) } @@ -279,7 +268,7 @@ func renameEntityFile(dataDir, subdir, oldID, newID string) (string, string, []b } // Rename in one journaled transaction: a failed write or source removal // must not leave the entity in two directories. - txn := persistence.NewTransaction(filepath.Join(dataDir, ".journal")) + txn := persistence.NewTransaction(persistence.JournalDir(dataDir)) if err := txn.Move(oldPath, newPath); err != nil { return "", "", nil, fmt.Errorf("rename: %w", err) } @@ -335,7 +324,7 @@ func deleteEntityDir(dataDir, subdir, dir string) ([]ChangeDesc, error) { } var changes []ChangeDesc - txn := persistence.NewTransaction(filepath.Join(dataDir, ".journal")) + txn := persistence.NewTransaction(persistence.JournalDir(dataDir)) for _, e := range entries { if e.IsDir() || filepath.Ext(e.Name()) != ".yaml" { continue -- cgit v1.2.3