From 1cc00f6a484d30c43b54e77dfff9450e939c857f Mon Sep 17 00:00:00 2001 From: Ave Date: Sun, 10 Jan 2021 03:39:47 +0300 Subject: [PATCH] patchport: Fix #92 --- patchport.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/patchport.py b/patchport.py index 681ffbd..e7bb5ab 100644 --- a/patchport.py +++ b/patchport.py @@ -54,23 +54,25 @@ def fix_offset(patch_contents): for line in patch_lines: if "diff -crB" in line: patch_target = line.split(" ")[2].replace("from/", "") + if not os.path.exists(os.path.join(apk_folder, patch_target)): + return False os.makedirs(os.path.dirname(os.path.join(tmp_folder, patch_target)), exist_ok=True) shutil.copy(os.path.join(apk_folder, patch_target), os.path.join(tmp_folder, patch_target)) - #shutil.copytree(apk_folder, tmp_folder) + # shutil.copytree(apk_folder, tmp_folder) subprocess.run("patch -p1 --no-backup-if-mismatch --force", shell=True, input=patch_contents, text=True, cwd=tmp_folder, capture_output=True) out = subprocess.run(f"diff -crB {apk_folder} {tmp_folder}", shell=True, input=patch_contents, text=True, cwd=tmp_folder, capture_output=True) - + shutil.rmtree(tmp_folder, ignore_errors=True) actual_difflines = [] for line in out.stdout.splitlines(): if line[0:4] != "Only": actual_difflines.append(line) patch_out = ("\n".join(actual_difflines)+"\n").replace(apk_folder, "from").replace(tmp_folder, "to") - + return patch_out @@ -204,8 +206,14 @@ for patch in os.listdir(os.path.join(cutthecord_folder, "patches")): failures.append(patch) out_path += "-failed" elif "offset" in out.stdout: - patch_contents = fix_offset(patch_contents) - print(f"WARNING: {patch} has offsets which were auto corrected.") + temp_patch_contents = fix_offset(patch_contents) + if temp_patch_contents: + patch_contents = temp_patch_contents + print(f"WARNING: {patch} has offsets which were auto corrected.") + else: + print(f"FAILED: {patch} is missing files, please fix by hand.") + failures.append(patch) + out_path += "-failed" if debug: print(out.stdout)