From dff94db8a286d6b863305f84ace65e9806313331 Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 27 Dec 2024 19:10:26 +0100 Subject: CHA_CONFIG_DIR -> CHA_DIR It isn't really limited to config. It just happens to be in XDG_CONFIG_HOME because XDG basedirs suck. (W3M_DIR works similarly.) --- src/config/config.nim | 7 ++++++- src/main.nim | 4 ++-- src/server/loader.nim | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/config/config.nim b/src/config/config.nim index e5a33f61..68725b77 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -739,7 +739,8 @@ proc getNormalAction*(config: Config; s: string): string = proc getLinedAction*(config: Config; s: string): string = return config.line.getOrDefault(s) -proc openConfig*(dir: var string; override: Option[string]): PosixStream = +proc openConfig*(dir: var string; override: Option[string]; + warnings: var seq[string]): PosixStream = if override.isSome: if override.get.len > 0 and override.get[0] == '/': dir = parentDir(override.get) @@ -748,8 +749,12 @@ proc openConfig*(dir: var string; override: Option[string]): PosixStream = let path = getCurrentDir() / override.get dir = parentDir(path) return newPosixStream(path) + dir = getEnv("CHA_DIR") + if dir != "": + return newPosixStream(dir / "config.toml") dir = getEnv("CHA_CONFIG_DIR") if dir != "": + warnings.add("CHA_CONFIG_DIR is deprecated; use CHA_DIR instead") return newPosixStream(dir / "config.toml") dir = getEnv("XDG_CONFIG_HOME") if dir != "": diff --git a/src/main.nim b/src/main.nim index 22455239..5ef498a1 100644 --- a/src/main.nim +++ b/src/main.nim @@ -211,11 +211,11 @@ const defaultConfig = staticRead"res/config.toml" proc initConfig(ctx: ParamParseContext; config: Config; warnings: var seq[string]): Err[string] = - let ps = openConfig(config.dir, ctx.configPath) + let ps = openConfig(config.dir, ctx.configPath, warnings) if ps == nil and ctx.configPath.isSome: # The user specified a non-existent config file. return err("Failed to open config file " & ctx.configPath.get) - putEnv("CHA_CONFIG_DIR", config.dir) + putEnv("CHA_DIR", config.dir) ?config.parseConfig("res", defaultConfig, warnings) when defined(debug): if (let ps = newPosixStream(getCurrentDir() / "res/config.toml"); diff --git a/src/server/loader.nim b/src/server/loader.nim index f68c8f30..ef32e455 100644 --- a/src/server/loader.nim +++ b/src/server/loader.nim @@ -1428,7 +1428,7 @@ proc initLoaderContext(fd: cint; config: LoaderConfig): LoaderContext = putEnv("GATEWAY_INTERFACE", "CGI/1.1") putEnv("CHA_INSECURE_SSL_NO_VERIFY", "0") putEnv("CHA_TMP_DIR", config.tmpdir) - putEnv("CHA_CONFIG_DIR", config.configdir) + putEnv("CHA_DIR", config.configdir) putEnv("CHA_BOOKMARK", config.bookmark) return ctx -- cgit