From 88c55b39c07a45d6d593e395540a2188dcf34a7f Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 21 Feb 2026 16:11:26 +0800 Subject: [PATCH] Enhance configuration path resolution in LoadWithRoot function - Update the LoadWithRoot function in config.go to ensure DataRoot is set correctly when it is empty, and resolve relative database paths for SQLite3 driver based on the Root directory. - Improve handling of non-absolute paths for primary and secondary database connections, enhancing overall configuration management. --- config/config.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index ec1e860c..96f8a373 100644 --- a/config/config.go +++ b/config/config.go @@ -138,8 +138,20 @@ func LoadWithRoot(root string) Config { // DataRoot if cfg.DataRoot == "" { cfg.DataRoot = filepath.Join(cfg.Root, "data") - if !filepath.IsAbs(cfg.DataRoot) { - cfg.DataRoot, _ = filepath.Abs(cfg.DataRoot) + } + if !filepath.IsAbs(cfg.DataRoot) { + cfg.DataRoot = filepath.Join(cfg.Root, cfg.DataRoot) + } + + // Resolve DB relative paths based on Root + for i, dsn := range cfg.DB.Primary { + if !filepath.IsAbs(dsn) && (cfg.DB.Driver == "sqlite3" || cfg.DB.Driver == "") { + cfg.DB.Primary[i] = filepath.Join(cfg.Root, dsn) + } + } + for i, dsn := range cfg.DB.Secondary { + if !filepath.IsAbs(dsn) && (cfg.DB.Driver == "sqlite3" || cfg.DB.Driver == "") { + cfg.DB.Secondary[i] = filepath.Join(cfg.Root, dsn) } }