Update gcmtest.py

free space security check
This commit is contained in:
tmpz23 2022-01-29 08:58:54 +01:00 committed by GitHub
parent bedf0784d6
commit 1a4c369684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ import shutil
from time import time from time import time
__version__ = "0.0.5" __version__ = "0.0.6"
__author__ = "rigodron, algoflash, GGLinnk" __author__ = "rigodron, algoflash, GGLinnk"
__license__ = "MIT" __license__ = "MIT"
__status__ = "developpement" __status__ = "developpement"
@ -26,6 +26,12 @@ repack_path = Path("repack")
# if there is a way to create symlinks on GCM filesystem, it could create strange situations # if there is a way to create symlinks on GCM filesystem, it could create strange situations
def test_storage():
total, used, free = shutil.disk_usage("/")
if free - 10**12 < 3 * sum(path.stat().st_size for path in roms_path.glob('*') if path.is_file()):
raise Exception("Error - Not enought free space on the disk to run tests.")
def print_paths_differences(folder1_paths:list, folder2_paths:list): def print_paths_differences(folder1_paths:list, folder2_paths:list):
backup_paths = folder2_paths.copy() backup_paths = folder2_paths.copy()
for path in folder1_paths: for path in folder1_paths:
@ -64,7 +70,7 @@ def compare_GCM(folder1: Path, folder2: Path):
folder1_file_count = len(folder1_root_paths) folder1_file_count = len(folder1_root_paths)
print(f"compare \"{folder1}\" - \"{folder2}\" ({folder1_file_count} files)") print(f"compare \"{folder1}\" - \"{folder2}\" ({folder1_file_count} files)")
if folder1_file_count == 0: if folder1_file_count == 0:
raise Exception(f"ERROR - EMPTY FOLDER: {folder1}") raise Exception(f"Error - Empty folder: {folder1}")
len1 = len(folder1.parts) len1 = len(folder1.parts)
len2 = len(folder2.parts) len2 = len(folder2.parts)
@ -73,18 +79,18 @@ def compare_GCM(folder1: Path, folder2: Path):
folder2_paths = [Path(*path.parts[len2:]) for path in (folder2 / "root").glob('**/*')] folder2_paths = [Path(*path.parts[len2:]) for path in (folder2 / "root").glob('**/*')]
if folder1_paths != folder2_paths: if folder1_paths != folder2_paths:
print_paths_differences(folder1_paths, folder2_paths) print_paths_differences(folder1_paths, folder2_paths)
raise Exception(f"Folders \"{folder1}\" and \"{folder2}\" are different (not the same folders or files names).") raise Exception(f"Error - Folders \"{folder1}\" and \"{folder2}\" are different (not the same folders or files names).")
# 2. Compare sys files content # 2. Compare sys files content
if not compare_files(folder1 / "sys" / "apploader.img", folder2 / "sys" / "apploader.img"): if not compare_files(folder1 / "sys" / "apploader.img", folder2 / "sys" / "apploader.img"):
raise Exception(f"\"{folder1}/sys/apploader.bin\" and \"{folder2}/sys/apploader.bin\" are different.") raise Exception(f"Error - \"{folder1 / 'sys/apploader.bin'}\" and \"{folder2 / 'sys/apploader.bin'}\" are different.")
if not compare_files(folder1 / "sys" / "boot.dol", folder2 / "sys" / "boot.dol"): if not compare_files(folder1 / "sys" / "boot.dol", folder2 / "sys" / "boot.dol"):
raise Exception(f"\"{folder1}/sys/boot.bin\" and \"{folder2}/sys/boot.bin\" are different.") raise Exception(f"Error - \"{folder1 / 'sys/boot.bin'}\" and \"{folder2 / 'sys/boot.bin'}\" are different.")
for path1 in folder1_root_paths: for path1 in folder1_root_paths:
if path1.is_file(): if path1.is_file():
path2 = folder2/Path(*path1.parts[len1:]) path2 = folder2/Path(*path1.parts[len1:])
if not compare_files(path1, path2): if not compare_files(path1, path2):
raise Exception(f"\"{path1}/\" and \"{path2}\" are different.") raise Exception(f"Error - \"{path1}\" and \"{path2}\" are different.")
################################################## ##################################################
@ -92,15 +98,17 @@ def compare_GCM(folder1: Path, folder2: Path):
################################################## ##################################################
def gcmtool_unpack(iso_path:Path, folder_path:Path): def gcmtool_unpack(iso_path:Path, folder_path:Path):
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{folder_path}\"") != 0: if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{folder_path}\"") != 0:
raise Exception("Error while unpacking gcm.") raise Exception("Error while unpacking GCM.")
def gcmtool_pack(folder_path:Path, iso_path:Path): def gcmtool_pack(folder_path:Path, iso_path:Path):
if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{iso_path}\"") != 0: if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{iso_path}\"") != 0:
raise Exception("Error while packing gcm.") raise Exception("Error while packing GCM.")
def gcmtool_rebuild_fst(folder_path:Path): def gcmtool_rebuild_fst(folder_path:Path):
if os.system(f"python gcmtool.py -r \"{folder_path}\"") != 0: if os.system(f"python gcmtool.py -r \"{folder_path}\"") != 0:
raise Exception("Error while rebuilding FST.") raise Exception("Error while rebuilding FST.")
TEST_COUNT = 3
start = time() start = time()
print("###############################################################################") print("###############################################################################")
print("# Checking tests folder") print("# Checking tests folder")
@ -109,8 +117,10 @@ print("#########################################################################
if unpack_path.is_dir() or unpack2_path.is_dir() or repack_path.is_dir(): if unpack_path.is_dir() or unpack2_path.is_dir() or repack_path.is_dir():
raise Exception(f"Error - Please remove:\n-{unpack_path}\n-{unpack2_path}\n-{repack_path}") raise Exception(f"Error - Please remove:\n-{unpack_path}\n-{unpack2_path}\n-{repack_path}")
test_storage()
print("###############################################################################") print("###############################################################################")
print("# TEST 1/3") print(f"# TEST 1/{TEST_COUNT}")
print("# Comparing roms_path->unpack->[unpack_path] ROMs with [dolphin_unpack_path]") print("# Comparing roms_path->unpack->[unpack_path] ROMs with [dolphin_unpack_path]")
print("###############################################################################") print("###############################################################################")
# unpack ROM in unpack_path # unpack ROM in unpack_path
@ -124,7 +134,7 @@ for folder_path in unpack_path.glob("*"):
compare_GCM(folder_path, dolphin_unpack_path / folder_path.name) compare_GCM(folder_path, dolphin_unpack_path / folder_path.name)
print("###############################################################################") print("###############################################################################")
print("# TEST 2/3") print(f"# TEST 2/{TEST_COUNT}")
print("# Comparing [unpack_path]->pack->unpack->[unpack2_path]") print("# Comparing [unpack_path]->pack->unpack->[unpack2_path]")
print("###############################################################################") print("###############################################################################")
# repack unpack_path repack_path # repack unpack_path repack_path
@ -149,7 +159,7 @@ for folder_path in unpack_paths:
shutil.rmtree(unpack2_path) shutil.rmtree(unpack2_path)
print("###############################################################################") print("###############################################################################")
print("# TEST 3/3") print(f"# TEST 3/{TEST_COUNT}")
print("# Comparing [unpack_path]->rebuild_fst->repack->unpack->[unpack2_path]") print("# Comparing [unpack_path]->rebuild_fst->repack->unpack->[unpack2_path]")
print("###############################################################################") print("###############################################################################")
# rebuild unpack_path FSTs # rebuild unpack_path FSTs