Skip to content

Commit 77241f3

Browse files
authored
Support more cache directories on Windows (#612)
1 parent 10fb04c commit 77241f3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/config.cr

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ module Shards
2020
end
2121

2222
private def self.find_or_create_cache_path
23-
candidates = [
24-
ENV["SHARDS_CACHE_PATH"]?,
25-
ENV["XDG_CACHE_HOME"]?.try { |cache| File.join(cache, "shards") },
26-
ENV["HOME"]?.try { |home| File.join(home, ".cache", "shards") },
27-
ENV["HOME"]?.try { |home| File.join(home, ".cache", ".shards") },
28-
File.join(Dir.current, ".shards"),
29-
]
23+
candidates = {% begin %}
24+
[
25+
ENV["SHARDS_CACHE_PATH"]?,
26+
{% if flag?(:windows) %}
27+
ENV["LOCALAPPDATA"]?.try { |dir| File.join(dir, "shards", "cache") },
28+
ENV["USERPROFILE"]?.try { |home| File.join(home, ".cache", "shards") },
29+
ENV["USERPROFILE"]?.try { |home| File.join(home, ".shards") },
30+
{% else %}
31+
ENV["XDG_CACHE_HOME"]?.try { |cache| File.join(cache, "shards") },
32+
ENV["HOME"]?.try { |home| File.join(home, ".cache", "shards") },
33+
ENV["HOME"]?.try { |home| File.join(home, ".cache", ".shards") },
34+
{% end %}
35+
File.join(Dir.current, ".shards"),
36+
]
37+
{% end %}
3038

3139
candidates.each do |candidate|
3240
next unless candidate

0 commit comments

Comments
 (0)