about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-31 17:23:45 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-31 17:24:06 +0200
commit24490f82d4f6016dc9499f32182fd80059734313 (patch)
treeea80a2da090b8db2af2099fac720d0f2931acb90 /src/config
parentee94caf0628730135c8bd4b46dc913a50d7ae2b6 (diff)
downloadchawan-24490f82d4f6016dc9499f32182fd80059734313.tar.gz
config: fix -C with files not in CWD
Diffstat (limited to 'src/config')
-rw-r--r--src/config/config.nim18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index 4869d79c..063c32fc 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -682,7 +682,14 @@ proc parseConfig(config: Config; dir: string; t: TomlValue): ParseConfigResult =
       var includes = config.`include`
       config.`include`.setLen(0)
       for s in includes:
-        let res = config.parseConfig(dir, openFileExpand(dir, s))
+        let fs = openFileExpand(dir, s)
+        if fs == nil:
+          return ParseConfigResult(
+            success: false,
+            warnings: ctx.warnings,
+            errorMsg: "include file not found: " & s
+          )
+        let res = config.parseConfig(dir, fs)
         if not res.success:
           return res
         myRes.warnings.add(res.warnings)
@@ -713,12 +720,13 @@ proc parseConfig*(config: Config; dir, s: string; name = "<input>";
 const defaultConfig = staticRead"res/config.toml"
 
 proc readConfig(config: Config; dir, name: string): ParseConfigResult =
-  let fs = if name.len > 0 and name[0] == '/':
-    newFileStream(name)
+  let path = if name.len > 0 and name[0] == '/':
+    name
   else:
-    newFileStream(dir / name)
+    dir / name
+  let fs = newFileStream(path)
   if fs != nil:
-    return config.parseConfig(dir, fs)
+    return config.parseConfig(parentDir(path), fs)
   return ParseConfigResult(success: true)
 
 proc loadConfig*(config: Config; s: string) {.jsfunc.} =