aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/yaml_util.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/yaml_util.go')
-rw-r--r--internal/admin/yaml_util.go21
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