Skip to content

Commit

Permalink
Support more cache directories on Windows (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Feb 21, 2024
1 parent 10fb04c commit 77241f3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ module Shards
end

private def self.find_or_create_cache_path
candidates = [
ENV["SHARDS_CACHE_PATH"]?,
ENV["XDG_CACHE_HOME"]?.try { |cache| File.join(cache, "shards") },
ENV["HOME"]?.try { |home| File.join(home, ".cache", "shards") },
ENV["HOME"]?.try { |home| File.join(home, ".cache", ".shards") },
File.join(Dir.current, ".shards"),
]
candidates = {% begin %}
[
ENV["SHARDS_CACHE_PATH"]?,
{% if flag?(:windows) %}
ENV["LOCALAPPDATA"]?.try { |dir| File.join(dir, "shards", "cache") },
ENV["USERPROFILE"]?.try { |home| File.join(home, ".cache", "shards") },
ENV["USERPROFILE"]?.try { |home| File.join(home, ".shards") },
{% else %}
ENV["XDG_CACHE_HOME"]?.try { |cache| File.join(cache, "shards") },
ENV["HOME"]?.try { |home| File.join(home, ".cache", "shards") },
ENV["HOME"]?.try { |home| File.join(home, ".cache", ".shards") },
{% end %}
File.join(Dir.current, ".shards"),
]
{% end %}

candidates.each do |candidate|
next unless candidate
Expand Down

0 comments on commit 77241f3

Please sign in to comment.