patchport: Fix #92

This commit is contained in:
ave 2021-01-10 03:39:47 +03:00
parent f3ee05255c
commit 1cc00f6a48

View file

@ -54,6 +54,8 @@ def fix_offset(patch_contents):
for line in patch_lines: for line in patch_lines:
if "diff -crB" in line: if "diff -crB" in line:
patch_target = line.split(" ")[2].replace("from/", "") 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) 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.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)
@ -204,8 +206,14 @@ for patch in os.listdir(os.path.join(cutthecord_folder, "patches")):
failures.append(patch) failures.append(patch)
out_path += "-failed" out_path += "-failed"
elif "offset" in out.stdout: elif "offset" in out.stdout:
patch_contents = fix_offset(patch_contents) 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.") 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: if debug:
print(out.stdout) print(out.stdout)