diff options
author | bptato <nincsnevem662@gmail.com> | 2024-10-28 20:08:09 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-10-28 20:08:09 +0100 |
commit | 6c5922d5f0b2d9d7b6e4c39593c6892a65f74e54 (patch) | |
tree | 2485ae5f313f0dd017ba85e86404393e5945b470 /adapter | |
parent | bd4386923056c53e97f0865d846ef52d0666ca56 (diff) | |
download | chawan-6c5922d5f0b2d9d7b6e4c39593c6892a65f74e54.tar.gz |
config: refactor, accept more possible config dirs
I'm starting to favor dotfiles over XDG basedirs, but there's no reason why we couldn't have both. So now the search path is: 0. if config was set through -C, use that 1. $CHA_CONFIG_DIR is set -> $CHA_CONFIG_DIR/config.toml 2. $XDG_CONFIG_HOME is set -> $XDG_CONFIG_HOME/chawan/config.toml 3. ~/.config/chawan/config.toml exists -> use that 4. ~/.chawan/config.toml exists -> use that Notably, this makes it so the default directory is ~/.chawan *if* you don't have an existing config.toml file. So in that case known_hosts will be placed in ~/.chawan/known_hosts. However, configurations with a config in ~/.config/chawan/config.toml continue to work as expected, as for those the known_hosts file remains inside ~/.config/chawan/. Finally, I've added a default user CGI directory to reduce friction in setting CGI up. (Like known_hosts, it's also relative to whatever config dir you have.)
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/protocol/gemini.nim | 5 | ||||
-rw-r--r-- | adapter/protocol/lcgi.nim | 6 |
2 files changed, 0 insertions, 11 deletions
diff --git a/adapter/protocol/gemini.nim b/adapter/protocol/gemini.nim index 6bd656e4..29e10310 100644 --- a/adapter/protocol/gemini.nim +++ b/adapter/protocol/gemini.nim @@ -15,15 +15,10 @@ proc fopen(filename, mode: cstring): pointer {.importc, nodecl.} proc openKnownHosts(os: PosixStream): (File, string) = var path = getEnv("GMIFETCH_KNOWN_HOSTS") if path == "": - let oldPath = getConfigDir() & "gmifetch/known_hosts" let ourDir = getEnv("CHA_CONFIG_DIR") if ourDir == "": os.die("InternalError", "config dir missing") path = ourDir & '/' & "gemini_known_hosts" - # for backwards compat, TODO eventually remove this - # (this has a race, but oh well.) - if fileExists(oldPath) and not fileExists(path): - moveFile(oldPath, path) createDir(path.beforeLast('/')) let f = cast[File](fopen(cstring(path), "a+")) if f == nil: diff --git a/adapter/protocol/lcgi.nim b/adapter/protocol/lcgi.nim index c73926ec..590c63c8 100644 --- a/adapter/protocol/lcgi.nim +++ b/adapter/protocol/lcgi.nim @@ -200,9 +200,3 @@ proc connectSocket*(os: PosixStream; host, port: string; outIpv6: var bool): proc connectSocket*(os: PosixStream; host, port: string): PosixStream = var dummy = false return os.connectSocket(host, port, dummy) - -proc getEnvEmpty*(name: string; fallback = ""): string = - let res = getEnv(name, fallback) - if res != "": - return res - return fallback |