Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more cache directories on Windows #612

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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