From c69c31693b5090a08a517cf2265e1db3a7ed80e5 Mon Sep 17 00:00:00 2001 From: DefinetlyNotAI Date: Tue, 17 Sep 2024 14:27:23 +0400 Subject: [PATCH] Fixed critical bug with zipping Now it deletes any zips and hashes before creating new ones --- .idea/webResources.xml | 1 + CODE/Logicytics.py | 8 ++++++-- CODE/_zipper.py | 14 ++++++++++++++ DCO.md | 15 ++++++++------- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.idea/webResources.xml b/.idea/webResources.xml index 0558235..30b55eb 100644 --- a/.idea/webResources.xml +++ b/.idea/webResources.xml @@ -7,6 +7,7 @@ + diff --git a/CODE/Logicytics.py b/CODE/Logicytics.py index 3231f48..ce681cb 100644 --- a/CODE/Logicytics.py +++ b/CODE/Logicytics.py @@ -340,13 +340,17 @@ def __run_other_script(script: str) -> None: # Zip generated files if action == "modded": - zip_loc_mod, hash_loc = zip_and_hash("..\\MODS", "MODS", action) + zip_loc_mod, hash_loc, deleted_files_zip, deleted_files_hash = zip_and_hash("..\\MODS", "MODS", action) log.info(zip_loc_mod) log.debug(hash_loc) + log.debug(deleted_files_zip) + log.debug(deleted_files_hash) -zip_loc, hash_loc = zip_and_hash("..\\CODE", "CODE", action) +zip_loc, hash_loc, deleted_files_zip, deleted_files_hash = zip_and_hash("..\\CODE", "CODE", action) log.info(zip_loc) log.debug(hash_loc) +log.debug(deleted_files_zip) +log.debug(deleted_files_hash) # Attempt event log deletion attempt_hide() diff --git a/CODE/_zipper.py b/CODE/_zipper.py index 75d442a..59c6364 100644 --- a/CODE/_zipper.py +++ b/CODE/_zipper.py @@ -46,7 +46,19 @@ def move_files(filename: str): shutil.move(f"{filename}.hash", "../ACCESS/DATA/Hashes") +def check_and_delete_files_with_suffix(directory: str, suffix: str): + deleted_files = [] + for filename in os.listdir(directory): + if filename.endswith(suffix): + file_path = os.path.join(directory, filename) + os.remove(file_path) + deleted_files.append(file_path) + return deleted_files + + def zip_and_hash(path: str, name: str, action: str) -> tuple: + deleted_files_hash = check_and_delete_files_with_suffix('../ACCESS/DATA/Hashes', '.hash') + deleted_files_zip = check_and_delete_files_with_suffix('../ACCESS/DATA/Zip', '.zip') today = date.today() filename = f"Logicytics_{name}_{action}_{today.strftime('%Y-%m-%d')}" files_to_zip = get_files_to_zip(path) @@ -58,4 +70,6 @@ def zip_and_hash(path: str, name: str, action: str) -> tuple: return ( f"Zip file moved to ../ACCESS/DATA/Zip/{filename}.zip", f"SHA256 Hash file moved to ../ACCESS/DATA/Hashes/{filename}.hash", + deleted_files_zip, + deleted_files_hash ) diff --git a/DCO.md b/DCO.md index 429b1f4..2cb2fcb 100644 --- a/DCO.md +++ b/DCO.md @@ -1,12 +1,12 @@ - - - -
Developer Certificate of Origin
+-->
+
+
+Developer Certificate of Origin
 Version 1.1
 
 Copyright (C) 2024 Logicytics and its contributors.
@@ -39,4 +39,5 @@ By making a contribution to this project, I certify that:
     are public and that a record of the contribution (including all
     personal information I submit with it, including my sign-off) is
     maintained indefinitely and may be redistributed consistent with
-    this project or the open source license(s) involved.
+    this project or the open source license(s) involved. 
+