/{website,internal,docs,cmd}: integration tests and more split backend fixes
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const ConfigFileName = "metadata.json"
|
||||
@@ -37,7 +38,7 @@ func ConfigPath(beadsDir string) string {
|
||||
|
||||
func Load(beadsDir string) (*Config, error) {
|
||||
configPath := ConfigPath(beadsDir)
|
||||
|
||||
|
||||
data, err := os.ReadFile(configPath) // #nosec G304 - controlled path from config
|
||||
if os.IsNotExist(err) {
|
||||
// Try legacy config.json location (migration path)
|
||||
@@ -49,52 +50,79 @@ func Load(beadsDir string) (*Config, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading legacy config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Migrate: parse legacy config, save as metadata.json, remove old file
|
||||
var cfg Config
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("parsing legacy config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Save to new location
|
||||
if err := cfg.Save(beadsDir); err != nil {
|
||||
return nil, fmt.Errorf("migrating config to metadata.json: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Remove legacy file (best effort)
|
||||
_ = os.Remove(legacyPath)
|
||||
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
var cfg Config
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("parsing config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func (c *Config) Save(beadsDir string) error {
|
||||
configPath := ConfigPath(beadsDir)
|
||||
|
||||
|
||||
data, err := json.MarshalIndent(c, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshaling config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
if err := os.WriteFile(configPath, data, 0600); err != nil {
|
||||
return fmt.Errorf("writing config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) DatabasePath(beadsDir string) string {
|
||||
return filepath.Join(beadsDir, c.Database)
|
||||
backend := c.GetBackend()
|
||||
|
||||
// Treat Database as the on-disk storage location:
|
||||
// - SQLite: filename (default: beads.db)
|
||||
// - Dolt: directory name (default: dolt)
|
||||
//
|
||||
// Backward-compat: early dolt configs wrote "beads.db" even when Backend=dolt.
|
||||
// In that case, treat it as "dolt".
|
||||
if backend == BackendDolt {
|
||||
db := strings.TrimSpace(c.Database)
|
||||
if db == "" || db == "beads.db" {
|
||||
db = "dolt"
|
||||
}
|
||||
if filepath.IsAbs(db) {
|
||||
return db
|
||||
}
|
||||
return filepath.Join(beadsDir, db)
|
||||
}
|
||||
|
||||
// SQLite (default)
|
||||
db := strings.TrimSpace(c.Database)
|
||||
if db == "" {
|
||||
db = "beads.db"
|
||||
}
|
||||
if filepath.IsAbs(db) {
|
||||
return db
|
||||
}
|
||||
return filepath.Join(beadsDir, db)
|
||||
}
|
||||
|
||||
func (c *Config) JSONLPath(beadsDir string) string {
|
||||
|
||||
Reference in New Issue
Block a user