fix: unify DATA_DIR default to /var/lib/webhooker for all environments
All checks were successful
check / check (push) Successful in 1m4s

Remove devDataDir() XDG-based logic. Both dev and prod now default
DATA_DIR to /var/lib/webhooker. Update Dockerfile and README to match.
This commit is contained in:
user
2026-03-17 04:41:04 -07:00
parent 89af414037
commit 93968b6f10
4 changed files with 46 additions and 86 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strconv"
"strings"
@@ -80,23 +79,6 @@ func envInt(key string, defaultValue int) int {
return defaultValue
}
// devDataDir returns the default data directory for the dev
// environment. It uses $XDG_DATA_HOME/webhooker if set, otherwise
// falls back to $HOME/.local/share/webhooker. The result is always
// an absolute path so the application's behavior does not depend on
// the working directory.
func devDataDir() string {
if xdg := os.Getenv("XDG_DATA_HOME"); xdg != "" {
return filepath.Join(xdg, "webhooker")
}
home, err := os.UserHomeDir()
if err != nil {
// Last resort: use /tmp so we still have an absolute path.
return filepath.Join(os.TempDir(), "webhooker")
}
return filepath.Join(home, ".local", "share", "webhooker")
}
// nolint:revive // lc parameter is required by fx even if unused
func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
log := params.Logger.Get()
@@ -127,16 +109,11 @@ func New(lc fx.Lifecycle, params ConfigParams) (*Config, error) {
params: &params,
}
// Set default DataDir based on environment. All SQLite databases
// (main application DB and per-webhook event DBs) live here.
// Both defaults are absolute paths to avoid dependence on the
// working directory.
// Set default DataDir. All SQLite databases (main application DB
// and per-webhook event DBs) live here. The same default is used
// regardless of environment; override with DATA_DIR if needed.
if s.DataDir == "" {
if s.IsProd() {
s.DataDir = "/data"
} else {
s.DataDir = devDataDir()
}
s.DataDir = "/var/lib/webhooker"
}
if s.Debug {