Documentation
¶
Overview ¶
Package storage provides atomic file operations, backup rotation, and path resolution for Aether colony data files. It replaces the shell-based atomic-write.sh and path resolution logic from aether-utils.sh.
Index ¶
- func ResolveAetherRoot() string
- func ResolveDataDir() string
- type Store
- func (s *Store) AppendJSONL(path string, entry interface{}) error
- func (s *Store) AtomicWrite(path string, data []byte) error
- func (s *Store) BasePath() string
- func (s *Store) CreateBackup(path string) error
- func (s *Store) LoadJSON(path string, dest interface{}) error
- func (s *Store) LoadRawJSON(path string) ([]byte, error)
- func (s *Store) ReadFile(path string) ([]byte, error)
- func (s *Store) ReadJSONL(path string) ([]json.RawMessage, error)
- func (s *Store) RotateBackups(basePath string) error
- func (s *Store) SaveJSON(path string, data interface{}) error
- func (s *Store) SaveRawJSON(path string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveAetherRoot ¶
func ResolveAetherRoot() string
ResolveAetherRoot resolves the Aether root directory using a 3-tier fallback:
- AETHER_ROOT environment variable (if set)
- Git repository root (via git rev-parse --show-toplevel)
- Current working directory (fallback)
This matches the shell AETHER_ROOT resolution in atomic-write.sh:
if [[ -z "${AETHER_ROOT:-}" ]]; then
if git rev-parse --show-toplevel >/dev/null 2>&1; then
AETHER_ROOT="$(git rev-parse --show-toplevel)"
else
AETHER_ROOT="$(pwd)"
fi
fi
func ResolveDataDir ¶
func ResolveDataDir() string
ResolveDataDir resolves the colony data directory. If COLONY_DATA_DIR is set, it is returned directly. Otherwise, the default path AETHER_ROOT/.aether/data/ is returned.
This matches the COLONY_DATA_DIR override logic from the shell codebase where per-colony data directories are resolved via environment variable.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides thread-safe atomic file operations within a base directory. All file paths are resolved relative to basePath unless they are absolute.
func NewStore ¶
NewStore creates a new Store rooted at basePath. The directory is created if it does not exist.
func (*Store) AppendJSONL ¶
AppendJSONL appends a JSON entry as a single line to a JSONL file.
func (*Store) AtomicWrite ¶
AtomicWrite writes data to path atomically using a temporary file and rename. If path ends in .json, the content is validated as valid JSON before writing. On error, the temporary file is cleaned up.
func (*Store) CreateBackup ¶
CreateBackup copies the file at path to a timestamped backup file. If the original file does not exist, it returns nil (nothing to back up). Backup files are named: path + ".bak.{timestamp}" matching the shell pattern.
func (*Store) LoadRawJSON ¶
LoadRawJSON reads a JSON file and returns raw bytes.
func (*Store) ReadJSONL ¶
func (s *Store) ReadJSONL(path string) ([]json.RawMessage, error)
ReadJSONL reads all valid JSON lines from a JSONL file. Blank lines are skipped. Malformed lines are logged and skipped (not errored).
func (*Store) RotateBackups ¶
RotateBackups removes the oldest backup files beyond maxBackups. Backup files are identified by the glob pattern: path + ".bak.*" Files are sorted by modification time (newest first) and the oldest entries beyond the limit are deleted.