From 3af1745cbf177a0e808442dcb6d5b910b6405f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 19 Sep 2024 15:07:42 +0200 Subject: [PATCH] FIXUP: Also hash the current date --- dev_scripts/env.py | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/dev_scripts/env.py b/dev_scripts/env.py index e64f3a1d8..6d6bafca4 100755 --- a/dev_scripts/env.py +++ b/dev_scripts/env.py @@ -8,6 +8,7 @@ import subprocess import sys import urllib.request +from datetime import date DEFAULT_GUI = True DEFAULT_USER = "user" @@ -292,29 +293,24 @@ def distro_build(distro, version): def image_name_build_dev(distro, version): """Get the container image for the dev variant of a Dangerzone environment.""" - hash = get_files_hash( - [ - git_root() / "dev_scripts/env.py", # ? dev_scripts/** ? + hash = hash_files( + get_files_in("dev_scripts") + + [ git_root() / "pyproject.toml", git_root() / "poetry.lock", - ] + ], + include_current_date=True, ) return IMAGE_NAME_BUILD_DEV_FMT.format(distro=distro, version=version, hash=hash) -def get_folders_files(folders: list[str]) -> list[pathlib.Path]: - """Return the list of all files present in the given folders""" - files = [] - for folder in folders: - files.extend([p for p in (git_root() / folder).glob("**") if p.is_file()]) - return files - - def image_name_build_enduser(distro, version): """Get the container image for the Dangerzone end-user environment.""" - hash = get_files_hash(get_folders_files(["install/linux", "debian"])) + hash = hash_files( + get_files_in("install/linux", "debian"), include_current_date=True + ) return IMAGE_NAME_BUILD_ENDUSER_FMT.format( distro=distro, version=version, hash=hash ) @@ -326,17 +322,34 @@ def dz_version(): return f.read().strip() -def get_files_hash(file_paths: list[pathlib.Path]) -> str: - """Returns the hash value of a list of files using the sha256 hashing algorithm.""" +def hash_files( + file_paths: list[pathlib.Path], include_current_date: bool = False +) -> str: + """Returns the hash value of a list of files using the sha256 hashing algorithm. + + If specified, also adds the current date in the hash. + """ hash_obj = hashlib.new("sha256") for path in file_paths: with open(path, "rb") as file: file_data = file.read() hash_obj.update(file_data) + if include_current_date: + current_date = date.today().strftime("%Y-%m-%d") + hash_obj.update(current_date.encode()) + return hash_obj.hexdigest() +def get_files_in(*folders: list[str]) -> list[pathlib.Path]: + """Return the list of all files present in the given folders""" + files = [] + for folder in folders: + files.extend([p for p in (git_root() / folder).glob("**") if p.is_file()]) + return files + + class PySide6Manager: """Provision PySide6 RPMs in our Dangerzone environments.