aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAdones Pitogo <pitogo.adones@gmail.com>2023-07-11 13:31:50 +0800
committerChristian Lamparter <chunkeey@gmail.com>2023-07-15 22:24:50 +0200
commit4ab8abfbf7b1e4aa006507e220a4f2db17421845 (patch)
tree84ea2ad39d0c83637f22eaa1fe28c30c25f54493 /scripts
parent62496e9a1a0470ee7a4a7719073824defa81cb8c (diff)
downloadupstream-4ab8abfbf7b1e4aa006507e220a4f2db17421845.tar.gz
upstream-4ab8abfbf7b1e4aa006507e220a4f2db17421845.tar.bz2
upstream-4ab8abfbf7b1e4aa006507e220a4f2db17421845.zip
build: fix generation of large .vdi images
Instead of loading the whole image into the memory when generating the sha256 sum, we load the file in chunks and update the hash incrementally to avoid MemoryError in python. Also remove a stray empty line. Fixes: #13056 Signed-off-by: Adones Pitogo <pitogo.adones@gmail.com> (mention empty line removal, adds Fixes from PR) Signed-off-by: Christian Lamparter <chunkeey@gmail.com> (cherry picked from commit bdb4b78210cfb6bc8a6cda62fc990dd45ec3054c)
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/json_add_image_info.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/scripts/json_add_image_info.py b/scripts/json_add_image_info.py
index 0c441b9334..aded743bcc 100755
--- a/scripts/json_add_image_info.py
+++ b/scripts/json_add_image_info.py
@@ -13,7 +13,6 @@ if len(argv) != 2:
json_path = Path(argv[1])
file_path = Path(getenv("FILE_DIR")) / getenv("FILE_NAME")
-
if not file_path.is_file():
print("Skip JSON creation for non existing file", file_path)
exit(0)
@@ -37,7 +36,14 @@ def get_titles():
device_id = getenv("DEVICE_ID")
-hash_file = hashlib.sha256(file_path.read_bytes()).hexdigest()
+
+sha256_hash = hashlib.sha256()
+with open(str(file_path),"rb") as f:
+ # Read and update hash string value in blocks of 4K
+ for byte_block in iter(lambda: f.read(4096),b""):
+ sha256_hash.update(byte_block)
+
+hash_file = sha256_hash.hexdigest()
if file_path.with_suffix(file_path.suffix + ".sha256sum").exists():
hash_unsigned = (