From 98374694fed60472c5ad39b8e7c44d395bba4463 Mon Sep 17 00:00:00 2001 From: doylet Date: Sun, 27 Oct 2024 16:25:22 +1100 Subject: [PATCH] Allow relative XDG_CONFIG/CACHE_HOME paths By converting the environment variable if specified to an absolute path using the standard library. This allows passing a relative path like, XDG_CONFIG_HOME=config XDG_CACHE_HOME=cache To expand essentially into ${PWD}/config and ${PWD}/cache respectively. --- src/apps/chifra/pkg/config/config.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/apps/chifra/pkg/config/config.go b/src/apps/chifra/pkg/config/config.go index 6621384a52..621d4ebddf 100644 --- a/src/apps/chifra/pkg/config/config.go +++ b/src/apps/chifra/pkg/config/config.go @@ -186,15 +186,16 @@ func pathFromXDG(envVar string) (string, error) { return "", nil // it's okay if it's empty } - if xdg[0] != string(os.PathSeparator)[0] { - return "", usage.Usage("The {0} value ({1}), must be fully qualified.", envVar, xdg) - } + absXDGPath, err := filepath.Abs(xdg); + if err != nil { + return "", usage.Usage("The {0} value ({1}), could not be interpreted as an absolute path.", envVar, xdg) + } - if _, err := os.Stat(xdg); err != nil { - return "", usage.Usage("The {0} folder ({1}) must exist.", envVar, xdg) + if _, err := os.Stat(absXDGPath); err != nil { + return "", usage.Usage("The {0} folder ({1}) must exist.", envVar, absXDGPath) } - return filepath.Join(xdg, ""), nil + return filepath.Join(absXDGPath, ""), nil } func validateRpcEndpoint(chain, provider string) error {