Skip to content

Commit

Permalink
base: Store config cache in .xbstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Nov 3, 2024
1 parent 9c03119 commit d4dd2bd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
import errno
import filecmp
import hashlib
import json
import os
import re
Expand Down Expand Up @@ -264,9 +265,12 @@ def _read_yml(self, path, *, is_root):
options = {name: self.get_option_value(name) for name in self.all_options}

# Try to read the cached file.
cache_path = os.path.join(
os.path.dirname(noext_path), "." + os.path.basename(noext_path) + ".cache.xbstrap"
)
h = hashlib.sha256()
h.update(os.path.realpath(path).encode("utf-8"))
cache_name = h.hexdigest()

cache_dir = os.path.join(self.source_root, ".xbstrap", "cfg_cache")
cache_path = os.path.join(cache_dir, cache_name)
cached_yml = self._read_cfg_cache(cache_path, path, options=options)
if cached_yml is not None:
return cached_yml
Expand Down Expand Up @@ -313,10 +317,10 @@ def _read_yml(self, path, *, is_root):
"yml": yml,
"options": options,
}
temp_cache_path = noext_path + ".temp-cache.xbstrap"
with open(temp_cache_path, "w") as f:
json.dump(cache_dict, f)
os.rename(temp_cache_path, cache_path)
_util.try_mkdir(cache_dir, recursive=True)
with tempfile.NamedTemporaryFile("w+", dir=cache_dir, delete=False) as temp_f:
json.dump(cache_dict, temp_f)
os.rename(temp_f.name, cache_path)

return yml

Expand Down

0 comments on commit d4dd2bd

Please sign in to comment.