Harden asset-version fallback hashing separators
This commit is contained in:
committed by
GitHub
parent
3745eedd74
commit
66cacaaf9d
@@ -653,7 +653,7 @@ templates = Jinja2Templates(directory=os.path.join(_BASE_DIR, "templates"))
|
|||||||
# ── Static asset cache-busting ────────────────────────────────────
|
# ── Static asset cache-busting ────────────────────────────────────
|
||||||
|
|
||||||
def _compute_asset_version() -> str:
|
def _compute_asset_version() -> str:
|
||||||
"""Return a stable asset version string for cache-busting template assets."""
|
"""Return a 16-char asset version from Nix store hash or static/template metadata."""
|
||||||
nix_match = re.search(r"/nix/store/([a-z0-9]{32})-", os.path.realpath(_BASE_DIR))
|
nix_match = re.search(r"/nix/store/([a-z0-9]{32})-", os.path.realpath(_BASE_DIR))
|
||||||
if nix_match:
|
if nix_match:
|
||||||
return nix_match.group(1)[:16]
|
return nix_match.group(1)[:16]
|
||||||
@@ -674,7 +674,9 @@ def _compute_asset_version() -> str:
|
|||||||
except OSError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
hasher.update(path.encode())
|
hasher.update(path.encode())
|
||||||
|
hasher.update(b"\0")
|
||||||
hasher.update(f"{stat.st_mtime_ns}:{stat.st_size}".encode())
|
hasher.update(f"{stat.st_mtime_ns}:{stat.st_size}".encode())
|
||||||
|
hasher.update(b"\0")
|
||||||
return hasher.hexdigest()[:16]
|
return hasher.hexdigest()[:16]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user