diff options
| author | historia <[not public]> | 2026-10-05 18:16:47 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-05 18:16:47 -0400 |
| commit | 9d8c43cd68c960b9a6b8f781684f763e204a4498 (patch) | |
| tree | c9e2a02094a8700db29db2768a0d058ce259a4f4 /internal/admin/yaml_util.go | |
| parent | 7a15a5d70004b28bf2a710fa0f536af2446e5b17 (diff) | |
| download | thehouseoficarus-9d8c43cd68c960b9a6b8f781684f763e204a4498.tar.gz | |
fix: shared YAML encoder and journal directory, text cleanup
Diffstat (limited to 'internal/admin/yaml_util.go')
| -rw-r--r-- | internal/admin/yaml_util.go | 21 |
1 files changed, 5 insertions, 16 deletions
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 |
