Skip to content

Commit 80c208c

Browse files
committed
script: use "proper" (?) env vars to get windows directories
1 parent f002406 commit 80c208c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

build/cyan/script.lua

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cyan/script.tl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,28 @@ local cache_disabled = (function(): boolean
4444
return false
4545
end)()
4646

47+
local is_windows <const> = package.config:sub(1, 1) == "\\"
48+
4749
local cache_path <const> = (function(): lexical_path.Path
4850
local dir = os.getenv("CYAN_SCRIPT_CACHE_DIR")
4951
if dir then
5052
return (lexical_path.from_os(dir))
5153
end
52-
dir = os.getenv("XDG_CACHE_HOME")
53-
if dir then
54-
return lexical_path.from_os(dir) .. "cyan-script-cache"
55-
end
5654

57-
if package.config:sub(1, 1) == "\\" then
58-
dir = os.getenv("AppData")
59-
return (lexical_path.from_os(dir) .. "Temp") .. "cyan-script-cache"
55+
dir = is_windows and os.getenv("Temp") or os.getenv("XDG_CACHE_HOME")
56+
57+
if not dir then
58+
dir = is_windows and os.getenv("UserProfile") or os.getenv("HOME")
59+
if dir then
60+
dir = dir .. (is_windows and "\\_cache" or "/.cache")
61+
end
6062
end
61-
dir = os.getenv("HOME")
63+
6264
if not dir then
6365
cache_disabled = true
6466
return
6567
end
66-
return (lexical_path.from_os(dir) .. ".cache") .. "cyan-script-cache"
68+
return (lexical_path.from_os(dir) .. "cyan-script-cache")
6769
end)()
6870

6971
function script.disable_cache()

0 commit comments

Comments
 (0)