config: Ensure we always have an absolute path

Having this consistent across the code is handy when we're building
paths, counting separators and other path manipulation.
This commit is contained in:
Daniele Sluijters 2023-01-03 14:35:36 +01:00 committed by Anirudh Oppiliappan
parent 1e7b63814f
commit 8586d930a3
1 changed files with 11 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package config
import ( import (
"fmt" "fmt"
"os" "os"
"path/filepath"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@ -40,5 +41,15 @@ func Read(f string) (*Config, error) {
return nil, fmt.Errorf("parsing config: %w", err) return nil, fmt.Errorf("parsing config: %w", err)
} }
if c.Repo.ScanPath, err = filepath.Abs(c.Repo.ScanPath); err != nil {
return nil, err
}
if c.Dirs.Templates, err = filepath.Abs(c.Dirs.Templates); err != nil {
return nil, err
}
if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil {
return nil, err
}
return &c, nil return &c, nil
} }