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

Make cache_key portable #127

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ansible_compat/prerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

def get_cache_dir(project_dir: str) -> str:
"""Compute cache directory to be used based on project path."""
# we only use the basename instead of the full path in order to ensure that
# we would use the same key regardless the location of the user home
# directory or where the project is clones (as long the project folder uses
# the same name).
basename = os.path.basename(project_dir).encode(encoding="utf-8")
# 6 chars of entropy should be enough
cache_key = hashlib.sha256(os.path.abspath(project_dir).encode()).hexdigest()[:6]
cache_key = hashlib.sha256(basename).hexdigest()[:6]
cache_dir = (
os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
+ "/ansible-compat/"
Expand Down